![]() |
| | #1 | |||
| Registered User Join Date: Jun 2008 Location: NYC
Posts: 262
| Question about 'gets' and EOF Code: #include <stdio.h>
#include <string.h>
#define SIZE 81
#define LIM 100
#define STOP "quit"
int main(void)
{
char input[LIM][SIZE];
int ct = 0;
printf("Enter up to %d lines (type quit to quit):\n", LIM);
while (ct < LIM && gets(input[ct]) != NULL && strcmp(input[ct], STOP) != 0)
ct++;
printf("%d strings entered\n", ct);
return 0;
}
Quote:
Quote:
Quote:
| |||
| Sharke is offline | |
| | #2 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,203
| Is this another one of those trick questions at the end of Apocalypse Now where Brando snarls, "I don't seen any EOF at all"? Because if it is it ain't funny, really. |
| MK27 is offline | |
| | #3 | |
| MENTAL DETECTOR Join Date: Apr 2006 Location: United States
Posts: 3,295
| The gets function, like fgets, is usually written as a looped call to fread. Your question is answered in the manual: Quote:
And remember that when you send EOF from the console there is actually two pieces of data to read: the EOF, and a newline. If the newline weren't there, input would fail like you expect.
__________________ <Niggawatts> Writing is both mechanical and organic <Niggawatts> It's like a cyborg dragon. <Niggawatts> Writing is like a cyborg dragon. Last edited by whiteflags; 03-05-2009 at 11:45 PM. | |
| whiteflags is offline | |
| | #4 | ||
| Registered User Join Date: Nov 2008
Posts: 7
| Quote:
Quote:
| ||
| vyn is offline | |
| | #5 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,353
| vyn, start a new thread and post your current code.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|