Thread: want to chk first character in double array

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    187

    want to chk first character in double array

    hello i have a function that i have to make that stop at MAX or if it it has first line EOF but it doesnt work so i tried to minimize it abit then i puted it simple into 1 main and it still didnt work
    here is the code
    Code:
    #include <stdio.h>
    int main(void)
    {
        char array[10][100];
        int i;
        for(i=0;i<10;i++) {
              fgets(array[i],100,stdin);
              if(array[i][0]==EOF) {
                  puts("dude we are ........en breaking !!!!");
                  break;
                  }
              }
       return 0;
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    EOF is not a character. It is a special value returned by the fgetc() function to report end-of-file. To detect EOF, you should call feof(stdin) after the call to fgets().
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    fgets doesn't, hasn't, and won't put EOF into your character array. It returns NULL when the end of file is reached (and then, only when no characters were read).

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    yah i know but it has char * i didnt know EOF was not a character anyways i tried feof after the call for fgets it didnt detect it when i made cntrl z
    Code:
    #include <stdio.h>
    int main(void)
    {
        char array[10][100];
        int i;
        for(i=0;i<10;i++) {
              fgets(array[i],100,stdin);
              if(!feof(stdin))
                  puts("dude we found EOF");
              }
        
       getchar();
       return 0;
    }

  5. #5
    Novice
    Join Date
    Jul 2009
    Posts
    568
    From documentation of feof():
    Return Value
    A non-zero value is returned in the case that the End-of-File indicator associated with the stream is set.
    Otherwise, a zero value is returned.
    Your problem is somewhere here. Can you not not find it?
    Code:
    if(!feof(stdin))
                  puts("dude we found EOF");
              }

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    yah i read it wrong :P i thought be mean that non zero is present in case it present EOF

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Replies: 8
    Last Post: 11-12-2008, 11:25 AM
  3. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  4. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM
  5. Trying to make this code faster & Cramer
    By just2peachy in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2004, 10:54 AM