-1
I have the following program in C language:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, char *argv[]){
FILE *p;
char str[30], frase[]="Nome do arquivo :", resposta [80];
int i;
printf("Informe o nome do arquivo :\n");
fgets(str ,20,p);
for(i=0; str[i];i++)
if(str[i]== ’\n’)
str[i]=0;
if (!(p=fopen(str ,"w"))){
printf("Erro! Não é possível abrir o arquivo. \n");
exit (1);
}
fputs(frase ,p);
fputs(str ,p);
fclose(p);
p = fopen(str ,"r");
fgets(resposta,atoi (argv[1]) ,p);
printf("%s \n", resposta );
fclose(p);
return (0);
}
I am compiling through gcc of linux. I already made several changes, I increased the size of char lists and even then the error "segmentation fault" persists right at the start of the execution.
Could someone help me?
Thank you so much! I knew that the problem would be in this line pq when I used only gets() worked, but using fgets is much better.
– Amanda Briena