hello,
am running a c program in visual C++ 2010 express,when i type the below code it keep running and after it give me the message that myfilename.exe has encountered a problem and needs to close.when i choose ok it give me the output.when i change the while loop to for loop and decrease the loop counter to 4 (for (int n=0;n<4;n++)) it work fine.any idea plz
am running a c program in visual C++ 2010 express,when i type the below code it keep running and after it give me the message that myfilename.exe has encountered a problem and needs to close.when i choose ok it give me the output.when i change the while loop to for loop and decrease the loop counter to 4 (for (int n=0;n<4;n++)) it work fine.any idea plz
Code:
void distance()
{
FILE* output1;
FILE* output2;
char str[11];
int i=0;
int mslat,mslong,bslat,bslong;
output1 = fopen("fdf.txt", "r");
output2 = fopen("rd.txt", "w");
while (!feof(output1)) {
fscanf(output1, "%s ", &str);
if(strstr(str,"RxLev:") != NULL )
{
fprintf(output2,"\n");
i=1;
}//--------if
else if(i==1)
{
fprintf(output2,"%s\t", str);
i=2;
}
else if(i==2)
{
fscanf(output1, "%s ", &str);
fprintf(output2,"%s\t", str);
i=3;
}
else if(i==3)
{
fscanf(output1, "%s ", &str);
fprintf(output2,"%s\t", str);
//fprintf(output2,"%lf\t", mslong);
i=4;
}
else if(i==4)
{
fscanf(output1, "%s ", &str);
fscanf(output1, "%s ", &str);
fscanf(output1, "%s ", &str);
fprintf(output2,"%s\t", str);
i=5;
}
else if(i==5)
{
fscanf(output1, "%s ", &str);
fprintf(output2,"%s\t", str);
i=6;
}
}
fclose(output1);
fclose(output2);
return;
}