1

I am trying to read a text file separated by semicolons such as

3;7;9;

4;7;23;

However, every time I call

while ((c = getc(fp))!= EOF) 

     putchar(c);

it skips the first value (3) and only outputs:

;7;9;

4;7;23;

Is there any way to get the first value?

Thank you

GenieB
  • 11
  • 1
  • Show some [MCVE]. Compile your actual code with all warnings and debug info (`gcc -Wall -Wextra -g` with [GCC](http://gcc.gnu.org/)). Use the [`gdb` debugger](https://sourceware.org/gdb/onlinedocs/gdb/). Current question is off-topic on StackOverflow – Basile Starynkevitch Feb 19 '18 at 06:07

1 Answers1

0

using C Program.*/

include

int main(){

//file nane
const char *fileName="sample.txt";
//file pointer
FILE *fp;
//to store read character
char ch;

//open file in read mode
fp=fopen(fileName,"r");
if(fp==NULL){
    printf("Error in opening file.\n");
    return -1;
}
printf("Content of file\n");
while((ch=getc(fp))!=EOF){
    printf("%c",ch);
}
fclose(fp);

return 0;

}

Maaz Bin Musa
  • 479
  • 5
  • 9