2

When I printf the variable answer it contains several strange chars. What might be the reason?

int flag=0;
char answer[512];
char a[2];
a[1]='\0';

int c;
int status=1;
do {
      c = fgetc(pp);
      if( feof(pp) ) {
         break ;
        }
        if(c=='F' || status==0){
                a[0]=(char)c;
                strcat(answer,a);
                status=0;
        }
   } while(TRUE);
Tosh
  • 132
  • 1
  • 11

1 Answers1

2

strcat expects the destination string to be valid - which means it must be null terminated. You are not explicitly null terminating the answer string. Add answer[0]=0 before your loop.

MFisherKDX
  • 2,840
  • 3
  • 14
  • 25