Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control execution time in C
    text
    copied!<p>I have a C program which will print the prime numbers into a .txt file. I want program to ask me the execution time by minutes. Trying to solve with the piece of code.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; int main() { execute(); return(0); } int execute(int minute) { time_t now; time(&amp;now); struct tm *tmp = localtime(&amp;now); printf("How long you want to execute the program by minute? "); scanf("%d",&amp;minute); printf("%d %02d %02d\n",tmp-&gt;tm_hour, tmp-&gt;tm_min+minute, tmp-&gt;tm_sec); return(minute); } </code></pre> <p>and here also is the code that I want to run.</p> <pre><code>#include &lt;stdio.h&gt; int isprime(int x); int main(void) { int AX_REGISTER, BX_REGISTER; FILE *number, *primes; int forever = 1; while (forever) { if ((number = fopen("lastnumber.txt", "r")) == NULL) { fprintf(stderr, "Cannot read LASTNUMBER.txt file.\n"); return 1; } fscanf(number,"%d",&amp;AX_REGISTER); fclose(number); BX_REGISTER=AX_REGISTER; AX_REGISTER=AX_REGISTER+1; if ((number = fopen("lastnumber.txt", "w")) == NULL) { fprintf(stderr, "Cannot write LASTNUMBER.txt file.\n"); return 1; } fprintf(number,"%d\n",AX_REGISTER); fclose(number); if (isprime(BX_REGISTER)) { if ((primes = fopen("primes.txt", "a")) == NULL) { fprintf(stderr, "Cannot open PRIMES.txt file.\n"); return 1; } fprintf(primes,"%d\n",BX_REGISTER); fclose(primes); } } return 0; } int isprime(int x) { int i; for (i=2;i&lt;x;i++) { if (x%i==0) return 0; } return 1; } </code></pre> <p>Since I am a newbie in C programming language I can not solve it by myself. Can someone help me? </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