P
philbo30
Newbie here, working to mash together some code for a hobby project;
the code is:
int main()
{
char data[30];
FILE *ptr;
ptr=fopen("or.txt","r");
fflush(stdout);
freopen("parsed.txt", "w+", stdout);
while (feof(ptr)==0)
{
fgets(data,30,ptr);
if (data[1]=='7' && data[2]=='1') continue;
if (data[0]=='B' && data[1]=='L') continue;
if (data[0]=='E' && data[1]=='V') continue;
if (data[0]=='P' && data[1]=='R') continue;
if (data[0]=='B' && data[1]=='l') continue;
if (data[5]=='T' && data[6]=='H') continue;
if (data[0]=='P' && data[1]=='l') continue;
if (data[3]=='6') continue;
if (data[0]=='\n') continue;
printf("%s",data);
}
fclose(ptr);
return 0;
}
The goal is to open a file, remove those lines designated with
"continue" and then write the results to a new file. This compiles and
runs fine as an executable. However, when I attempt to call it as a
function within a larger program, it isn't able to write the results
to the new file, "parsed.txt", that file remains blank, and the
program "hangs". Any ideas?
In advance, thanks!
the code is:
int main()
{
char data[30];
FILE *ptr;
ptr=fopen("or.txt","r");
fflush(stdout);
freopen("parsed.txt", "w+", stdout);
while (feof(ptr)==0)
{
fgets(data,30,ptr);
if (data[1]=='7' && data[2]=='1') continue;
if (data[0]=='B' && data[1]=='L') continue;
if (data[0]=='E' && data[1]=='V') continue;
if (data[0]=='P' && data[1]=='R') continue;
if (data[0]=='B' && data[1]=='l') continue;
if (data[5]=='T' && data[6]=='H') continue;
if (data[0]=='P' && data[1]=='l') continue;
if (data[3]=='6') continue;
if (data[0]=='\n') continue;
printf("%s",data);
}
fclose(ptr);
return 0;
}
The goal is to open a file, remove those lines designated with
"continue" and then write the results to a new file. This compiles and
runs fine as an executable. However, when I attempt to call it as a
function within a larger program, it isn't able to write the results
to the new file, "parsed.txt", that file remains blank, and the
program "hangs". Any ideas?
In advance, thanks!