M
Materialised
Hi everyone,
I have the following program
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp1, *fp2;
char s[80];
if((fp1=fopen("/usr/local/www/cgi-bin/data.txt", "r"))==NULL)
{
printf("Cannot open file 1\n");
exit(1);
}
if((fp2=fopen("/usr/home/mick/data.txt", "w"))==NULL)
{
printf("Cannot open file 2\n");
exit(1);
}
while(!feof(fp1))
{
fscanf(fp1, "%s", s);
fprintf(fp2, "%s\n", s);
}
fclose(fp1);
fclose(fp2);
return 0;
}
However it gives me a segmentation fault.
The permissions on the file(s) are not the issue, but if I change the
code to read
if((fp1=fopen("data.txt", "r"))==NULL)
{
printf("Cannot open file 1\n");
exit(1);
}
if((fp2=fopen("output.txt", "w"))==NULL)
{
printf("Cannot open file 2\n");
exit(1);
}
The code works fine.
Does anyone know the issue here?
I have the following program
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp1, *fp2;
char s[80];
if((fp1=fopen("/usr/local/www/cgi-bin/data.txt", "r"))==NULL)
{
printf("Cannot open file 1\n");
exit(1);
}
if((fp2=fopen("/usr/home/mick/data.txt", "w"))==NULL)
{
printf("Cannot open file 2\n");
exit(1);
}
while(!feof(fp1))
{
fscanf(fp1, "%s", s);
fprintf(fp2, "%s\n", s);
}
fclose(fp1);
fclose(fp2);
return 0;
}
However it gives me a segmentation fault.
The permissions on the file(s) are not the issue, but if I change the
code to read
if((fp1=fopen("data.txt", "r"))==NULL)
{
printf("Cannot open file 1\n");
exit(1);
}
if((fp2=fopen("output.txt", "w"))==NULL)
{
printf("Cannot open file 2\n");
exit(1);
}
The code works fine.
Does anyone know the issue here?