Jump to content

fgetc problem

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Omar Ali

Omar Ali

    Newbie

  • Members
  • Pip
  • 4 posts
#include <stdio.h>     

#include <string.h>      

int main ()     

{

    char c;

    char string[100];

    FILE *fp;

    fp=fopen("mytext.txt","r++");

    fgets(string,sizeof(string),fp);

    //printf("%s\n",string);

    do {

    c = fgetc(fp);

    if (c == 'a') {printf("we have an A");}

}while(c != EOF);         


system("PAUSE");

return 0;

} 

what's wrong ?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Well, you're doing a comparison before checking for EOF. That looks fishy. Are you getting an error message?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Does r++ mode even work?
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users