Error when running program
Below is the code for my program. It does everything I want it to, but then at the end of running it an error appears. I can't figure out why it gives an error after doing everything I told it to successfully.
any help?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
main()
{
int i,j,k,q=0;
FILE *fp, *fp2;
char s[N]={"\0"}, word2[N]={"\0"}, str[N]={"\0"}, file2word1[N]={"\0"}, file2word2[N]={"\0"};
fp = fopen("check.out", "w");
gets(s);
fprintf(fp, "%s\n", str);
printf("Line input has been added to check.out\n");
fclose(fp);
for(i=0; s[i]!='\0';i++)
{
if(s[i]==' ')
break;
}
for(j=i+1, k=0; s[j]!=' '; j++, k++)
{
word2[k]=s[j];
}
if(word2[0]=='\0')
{
printf("There is no second word in the input text.\nFile opening not tried.\n");
q++;
goto next;
}
if(q!=1)
{
if((fp2 = fopen(word2, "r")) == NULL)
{
printf("Tried opening file '%s'\nFile opening failed - file does not exist.\n", word2);
q++;
}
}
next:
if(q!=1)
{
fp2=fopen(word2, "r");
fscanf(fp2, "%s", &file2word1);
fscanf(fp2, "%s", &file2word2);
printf("Tried opening file '%s'\nFile opening successful - %s found and opened.\nSecond word in %s is '%s'", word2, word2, word2, file2word2);
}
return 0;
}