Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat line is at fault -- segfault, that is...?
    text
    copied!<p>I'm relatively new to C (and completely new to StackOverflow - hey guys!), and this segfault has been giving me no surcease of sorrow for the past few hours (DevC++ on a windows machine). It's just a simple palindrome prime program, but it's really giving me a hard time. I'm not generally a novice programmer like it seems here, but... Good god. Now I remember why I wanted to get away from C++ and to Python so quickly.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;errno.h&gt; #include &lt;string.h&gt; FILE *outputFile; char buffer[81]; char* strrev(); int bytesWritten; char* strI = 0; char *strrev(char str[]) { char *p1 =NULL; char *p2 =NULL; if (! str || ! *str) return str; for (p1 = str, p2 = str + strlen(str) - 1; p2 &gt; p1; ++p1, --p2) { *p1 ^= *p2; *p2 ^= *p1; *p1 ^= *p2; } return str; } main() { int isPrime(int); int i,j; outputFile = fopen("DD:OUTPUT", "w"); if (outputFile == NULL) { printf("open error: %d/%s\n", errno, strerror(errno)); exit(99); } for (i=1; i&lt;15000; i++) { if (isPrime(i)==1) { bytesWritten = sprintf(buffer,"%d is primepal!\n",i); fwrite(buffer, 1, bytesWritten, outputFile); } } fclose(outputFile); return 0; } int isPrime(int myInt) { int loop; for (loop = 2; loop &lt; myInt/2+1; loop++) sprintf(strI, "%s%d", 10, myInt); { if (myInt%loop==0 &amp;&amp; (atoi(strrev(strI))-myInt)==0) { return 0; } return 1; } } </code></pre> <p>I apologize ahead of time if this is a dumb question, and the answer is very obvious -- but I've officially hit the limit where no matter how logical an answer, I've been coding the same problem for too long for it to make any sense. And also, segfaults are horrible beasts. Thank you ahead of time for anything you have to offer!</p> <p>~ Jordan </p>
 

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