I am doing an exercise in C to brush myself up on the topic. I am trying to use my program to manipulate header files; but the program returns "Segmentation fault". I have isolated the issue to the following segment of code. Can any one help me see what exactly is wrong with it ?
header=strtok(st,"\"");
header=strtok(NULL,"\"");
f=fopen(header,"r");
if(f)
{
while((ch=fgetc(f))!=EOF)
fputc(ch,f2);
fclose(f);
}
else
{
header2=(char *)malloc(strlen("/usr/include")+strlen(header));
header2=strcat("/usr/include/",header);
f=fopen(header2,"r");
printf("%s\n",header2);
while((ch=fgetc(f))!=EOF)
fputc(ch,f2);
fclose(f);
}
I have noted that the issue occurs only when I am trying to access the /usr/include/ location. Some sort of authentication issue ? If so, how to over come it ? Thanks in advance. :)