Note that there are some explanatory texts on larger screens.

plurals
  1. POHow could I go about finding the error from opening the file?
    primarykey
    data
    text
    <p>Fopen and Fclose are wrapper functions in my source file that check for errors when opening the file. when I run my program, it says there was an Fopen error. I see no reason for an error during the file opening.</p> <p>Sorry for the long code. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;ctype.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include "perry.h" int main(void) { void copyStrings(char *infile, char *outfile, char ch); void compareFiles(char *infile, char *outfile); char inputfile[80]; char outputfile[80]; char ch; printf("Enter input filename: "); scanf("%s", inputfile); printf("Enter output filename: "); scanf("%s", outputfile); printf("Enter a character: "); scanf(" %c", &amp;ch); if(!isalpha(ch)) { printf("Did not enter a letter!"); exit(1); } copyStrings(inputfile, outputfile, ch); compareFiles(inputfile, outputfile); return 0; } void copyStrings(char *infile, char *outfile, char ch) { int count; char *ptr; char *line; char linePart[80]; FILE *fin; FILE *fout; fin = Fopen(infile, "r"); fout = Fopen(outfile, "w"); while(fgets(line, 80, fin) != NULL) { for(ptr=line;ptr&lt;line+strlen(line);ptr++) { if(*ptr == ch) count ++; } if(count &lt; 2) fputs(line, fout); else { memset(linePart, '\0', strlen(line)+1); line = strchr(line, ch); strncpy(linePart, line, strchr(line+1, ch) - line + 1); fputs(linePart, fout); fprintf(fout, "\n"); } } Fclose(fout); Fclose(fin); return; } void compareFiles(char *infile, char *outfile) { int count = 0; char inputString[80]; char outputString[80]; FILE *fin; FILE *fout; fin = Fopen(infile, "r"); fout = Fopen(outfile, "r"); while(fgets(inputString, 80, fin) != NULL) { count += 1; if(strcmp(inputString, fgets(outputString, 80, fout)) == 0) { printf("Strings are equal at line %d\n\nBoth strings look like this: %s", count, inputString); } } Fclose(fout); Fclose(fin); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload