0
main()
{
    FILE *fin;
    char line[50];
    char exp[SIZE];
    fin=fopen("prefix.txt","r");

    if(fin==NULL)
    {
         printf("\nFile Cannot be Opened\n");
    }
    else
    {
         printf("\nfile opened\n");

         while(fgets(line, sizeof(line), fin)!=NULL)
         {
              sscanf(line, "%s", exp);
              delete_spaces(exp);
              convert(exp);
         }
    }
    fclose(fin);
    getch();
}

My file is containing string with spaces and when I am reading a line from it, the line is containing only first word and ignoring string after space.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user39495
  • 151
  • 1
  • 9

2 Answers2

1

Yeah, because sscanf() (along with all the scanf() functions) uses the %s specifier to read a string up to the first whitespace character. So you explicitly truncate your line with that one call. It seems to me that you want to process the entire line, so that sscanf is just useless -- remove it.

user3447428
  • 125
  • 4
0

you need to use the EOF statement to read the file entirely , e.g in your case :

while ((line = getc(fin)) != EOF)
Rage91
  • 87
  • 1
  • 9