I am writing a program to open a file (say "input_file"), manipulate its contents and then output it to another file ("manipulated-input_file")
I have done this with strcpy and strcat in the following way:
char t-filename[]="Manipulated-", filename[50], td-filename[50];
memset ( filename, '\0', FILE_NAME);
printf("Please enter the filename - \n");
scanf( "%30s", filename );
strcpy(td-filename,filename);
strcat(t-filename,td-filename);
printf("%s\n", t-filename);
Now printf functions prints the t-filename as "Manipulated-input_file"
After this part, I have a section where I open "input_file" and do something.
fptr = fopen(filename, "r");
while ( fgets (line, sizeof line, fptr) != NULL)
{
...do something...
}
fclose(fptr);
Later I wanted to open a file with name 't-filename' at the end of the code:
tptr = fopen(t-filename, "w");
fprintf(tptr,"something");
fclose(tpr);
When I compile this code I am getting "Segmentation fault (core dumped)".
I do not know what went wrong. Can somebody help?