?
Solved

end of file equivalent command on windows 98 for use in gets()

Posted on 2003-03-20
2
Medium Priority
?
215 Views
Last Modified: 2010-04-15
Hi,

I am trying to implement the following code. I am able to run the code on unix using ctrl-d for end of file for gets() but I am not able to figure out how to stop gets() from taking any input on windows 98 as ctrl-d doesn't seem to work or I cannot find the end of file indicator. I am using MS Visual C++ 6.0 compiler. Any hepl will be appreciated

Regards,
Sid

#include <stdio.h>
#include "lists.h"
int main ( ) {
     char word[100];
     printf ("Collecting names into a list.\n");
     struct ListNode * list = newList ( );
     while (gets(word)) {
     list = cons (word, list);
     }
     printf ("Printing the names in the list.\n");
     print (list);
     return 0;
}

YOU CAN IGNORE THE CODE BELOW

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lists.h"

struct ListNode  /* You supply this definition. */
     {
     char *name;   /* points to the name */
    struct ListNode *next; /*next list */
     };
/* Return an empty linked list. */
struct ListNode * newList ( ) {
return 0;
}


/* Return the result of adding the given string to the front of the given list. */
struct ListNode * cons (char *s, struct ListNode * list) {
/* You supply the body of this function. */
     struct ListNode *newnode;
     newnode =(struct ListNode *) malloc(sizeof(ListNode)) ; //allocate memory from heap
     newnode->name =s; // point the name to the new string
     newnode->next =list; // set next pointer to list;
     list=newnode;  // update list to get it ready for the next iteration
     return newnode;
     }
/* Print the names in the given linked list, one per line. */

void print (struct ListNode * list) {
if (list != 0) {
printf ("%s\n", list->name);
print (list->next);
}
}
0
Comment
Question by:cplus2java
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 300 total points
ID: 8177590
Try using Ctrl-Z as an EOF indicator.
0
 

Author Comment

by:cplus2java
ID: 8179025
thanks -ctrl z worked
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question