# Segmentation fault when using fopen("filename","w+")

Printable View

• 11-20-2011
Marslakoo
Segmentation fault when using fopen("filename","w+")
Hello,
Please help. I have no idea what's wrong with fopen with this time....
Code:

``` #include <stdio.h>#include <stdlib.h> #include <math.h> #define xfirst 0 #define xlast 300 #define tfirst 10 #define tlast 300 #define N 40 #define M 5 FILE *fpout; main(){ /*FÜGGVÉNYEK*/ void forward(int number,double fwghost[], double dx,double *results[]) {     int i;     for(i=0;i<N;i++){         *results[i]=(fwghost[i+2]-fwghost[i+1])/dx; } }/*forward*/ void central(int number,double fwghost[], double dx,double *results[]) {     int i;     for(i=0;i<N;i++){     *results[i]=(fwghost[i+2]-fwghost[i])/(2*dx); } }/*central*/ double secondc(int number,double fwghost[], double dx,double *results[]) {     int i;     for(i=0;i<N;i++){     *results[i]=(fwghost[i+2]+2*fwghost[i+1]-fwghost[i])/(dx*dx); } }/*secondd*/ /*DEKLARÁCIÓK, ÉRTELMEZÉSI TARTOMÁNY*/ int i,j,k; double t[M+2],x[N+2],u[N],u_anal[N],u_deriv[N],u_ghost[N+2]; double v=5.; double dx=(xlast-xfirst)/(N-1); double dt=(tlast-tfirst)/(M-1); for(i=1;i<N+1;i++) x[i]=xfirst+dx*i; x[0]=x[1]-dx; x[N+1]=x[N]+dx; for(i=1;i<M+1;i++) t[i]=tfirst+dt*i; t[0]=t[1]-dt; t[N+1]=t[N]+dt; /*ANALITIKUS*/ for(i=0;i<M;i++){ for(j=0;j<N;j++){ u_anal[j]=1/(1+exp((2*x[j+1]-t[i])/(4*v))); printf("%0.2lf %0.15lf\n",x[j+1],u_anal[j]); }/*for j*/ }/*for i*/ printf("analitikus lefutott."); for(j=0;j<N+1;j++){ u_ghost[j]=1/(1+exp((2*x[j]-t[0])/(4*v))); }/*for j*/ printf("u_ghost kész."); /*KIÍRATÁS*/ fpout=fopen("burgers_anal.dat","w+"); for(j=0;j<N;j++){ fprintf(fpout,"%0.2lf %0.15lf\n",x[j+1],u_anal[j]); }/*for j*/ //fclose(fpout); fflush(fpout); }```
I get segmentation fault when i try to write the data in file. I have never had this kind of problem. I read a few posts about this kind of seg. f., but I still don't get what's the problem with my code.
• 11-20-2011
JohnGraham
A segfault can occur because of data corruption from anywhere in a program, and can be caused by data corruption that occurred earlier in the program. In your case, the line:

Code:

`t[N + 1] = t[N] + dt;`
is giving you the trouble, because t[] has a dimension of 7 (M+2) but you're accessing indexes N and N+1 (40 and 41).
• 11-20-2011
CommonTater
Line 1 .. you have 2 preprocessor statments on the same line... C doesn't know how to do that

Line 11... fpout is declared at global scope but only used in main...

Line 14... unless this is for a microcontroller, the OS will expect an integer return value from main()... The correct form is...
Code:

```int main (void)   {     // your code goes here     return 0; }```
This matters because even if your program appears to work correctly it can cause problems for the OS itself since scripts, batch files and parent programs often rely upon the return value from main() to determine success or failure.

Lines 18 to 42 ... You are declaring functions inside your main... C does not support "nested" functions...

Line 82... you did not check to see if the file actually opens but proceeded to write to it anyway.

Line 86 and 87 ... you should not be flushing a file after closing it... and you shouldn't do either if you're not certain it actually opened.

You seriously need to learn how to indent code according to some rational scheme... Standards.. HERE
• 11-21-2011
Marslakoo
Thank both of you!

I haven't realized this
Code:

`t[N + 1] = t[N] + dt;`
because the code was running without the fopen().
Thanks for the advices. :)
• 11-21-2011
CommonTater
Quote:

Originally Posted by Marslakoo
because the code was running without the fopen().
Thanks for the advices. :)

Your code has never worked...
Here are the error messages I get from Pelles C (C-99 standard)... Pay special attention to the last 3 lines...
Code:

```Building main.obj. D:\Programming\C_Code\Experiments\junk\main.c(1): error #1036: Syntax error in #include. D:\Programming\C_Code\Experiments\junk\main.c(11): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(11): error #2001: Syntax error: expected ';' but found '*'. D:\Programming\C_Code\Experiments\junk\main.c(11): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(14): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(14): warning #2117: Old-style function definition for 'main'. D:\Programming\C_Code\Experiments\junk\main.c(19): error #2001: Syntax error: expected ';' but found '{'. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2048: Undeclared identifier 'results'. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2144: Type error: pointer expected. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2144: Type error: pointer expected. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2048: Undeclared identifier 'fwghost'. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2144: Type error: pointer expected. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2144: Type error: pointer expected. D:\Programming\C_Code\Experiments\junk\main.c(22): error #2048: Undeclared identifier 'dx'. D:\Programming\C_Code\Experiments\junk\main.c(27): warning #2118: Parameter 'number' is not referenced. D:\Programming\C_Code\Experiments\junk\main.c(36): warning #2118: Parameter 'number' is not referenced. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2111: Integer expression must be constant. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2120: Redeclaration of 'x', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(47); expected 'double [42]' but found 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(55): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(55): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(56): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(56): error #2123: Redefinition of 'x', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(55). D:\Programming\C_Code\Experiments\junk\main.c(56): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(56): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(56): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(57): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(57): error #2120: Redeclaration of 'x', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(56); expected 'int [1]' but found 'int [41]'. D:\Programming\C_Code\Experiments\junk\main.c(57): error #2123: Redefinition of 'x', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(56). D:\Programming\C_Code\Experiments\junk\main.c(57): error #2098: Missing '{' in initialization of 'int [41]'. D:\Programming\C_Code\Experiments\junk\main.c(57): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(57): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2123: Redefinition of 'i', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(55). D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2111: Integer expression must be constant. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2120: Redeclaration of 't', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(47); expected 'double [7]' but found 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(58): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(58): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(59): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(59): error #2123: Redefinition of 't', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(58). D:\Programming\C_Code\Experiments\junk\main.c(59): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(59): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(59): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(60): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(60): error #2120: Redeclaration of 't', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(59); expected 'int [1]' but found 'int [41]'. D:\Programming\C_Code\Experiments\junk\main.c(60): error #2123: Redefinition of 't', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(59). D:\Programming\C_Code\Experiments\junk\main.c(60): error #2098: Missing '{' in initialization of 'int [41]'. D:\Programming\C_Code\Experiments\junk\main.c(60): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(60): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(64): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2123: Redefinition of 'i', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(58). D:\Programming\C_Code\Experiments\junk\main.c(64): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(64): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(64): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(64): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(65): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(65): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(66): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(66): error #2111: Integer expression must be constant. D:\Programming\C_Code\Experiments\junk\main.c(66): error #2120: Redeclaration of 'u_anal', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(47); expected 'double [40]' but found 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(66): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(66): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(66): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(67): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(67): error #2001: Syntax error: expected ')' but found 'string constant'. D:\Programming\C_Code\Experiments\junk\main.c(67): warning #2028: Missing prototype. D:\Programming\C_Code\Experiments\junk\main.c(68): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(69): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(70): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(70): error #2001: Syntax error: expected ')' but found 'string constant'. D:\Programming\C_Code\Experiments\junk\main.c(70): warning #2028: Missing prototype. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2123: Redefinition of 'j', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(65). D:\Programming\C_Code\Experiments\junk\main.c(73): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(73): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(74): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(74): error #2111: Integer expression must be constant. D:\Programming\C_Code\Experiments\junk\main.c(74): error #2120: Redeclaration of 'u_ghost', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(47); expected 'double [42]' but found 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(74): error #2098: Missing '{' in initialization of 'int [1]'. D:\Programming\C_Code\Experiments\junk\main.c(74): warning #2215: Conversion from 'double' to 'int'; possible loss of data. D:\Programming\C_Code\Experiments\junk\main.c(74): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(75): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(78): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(78): error #2001: Syntax error: expected ')' but found 'string constant'. D:\Programming\C_Code\Experiments\junk\main.c(78): warning #2028: Missing prototype. D:\Programming\C_Code\Experiments\junk\main.c(82): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(82): error #2120: Redeclaration of 'fpout', previously declared at D:\Programming\C_Code\Experiments\junk\main.c(11); expected 'int *' but found 'int'. D:\Programming\C_Code\Experiments\junk\main.c(82): warning #2027: Missing prototype for 'fopen'. D:\Programming\C_Code\Experiments\junk\main.c(82): error #2069: Initializer must be constant. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(83): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2001: Syntax error: expected ')' but found '='. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2123: Redefinition of 'j', previously defined at D:\Programming\C_Code\Experiments\junk\main.c(73). D:\Programming\C_Code\Experiments\junk\main.c(83): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2001: Syntax error: expected ';' but found '<'. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2156: Unrecognized declaration. D:\Programming\C_Code\Experiments\junk\main.c(83): warning #2014: Empty declaration. D:\Programming\C_Code\Experiments\junk\main.c(83): warning #2099: Missing type specifier; assuming 'int'. D:\Programming\C_Code\Experiments\junk\main.c(83): error #2001: Syntax error: expected ';' but found '++'. D:\Programming\C_Code\Experiments\junk\main.c(83): fatal error #2210: More than 100 errors, please improve yourself. If you are compiling a Windows program, make sure you use the /Ze option! *** Error code: 1 ***```
• 11-21-2011
JohnGraham
Quote:

Originally Posted by CommonTater
Your code has never worked...

His code certainly has worked - all the errors you see are caused by the double-#include on the first line, which is probably a simple cut & paste error. Fix that and I just get from gcc is a few warnings about unused variables and no return value.
• 11-21-2011
CommonTater
Quote:

Originally Posted by JohnGraham
His code certainly has worked - all the errors you see are caused by the double-#include on the first line, which is probably a simple cut & paste error. Fix that and I just get from gcc is a few warnings about unused variables and no return value.

Well... that and functions defined inside main(), array bounds errors, etc...

Still gives that classic Pelles C error message: "More than 100 errors, please improve yourself."

However... if I change it like this...
Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> #define xfirst 0 #define xlast 300 #define tfirst 10 #define tlast 300 #define N 40 #define M 5 void forward(int number,double fwghost[], double dx,double *results[])   {     int i;     for(i=0;i<N;i++)       {         *results[i]=(fwghost[i+2]-fwghost[i+1])/dx;       }   } void central(int number,double fwghost[], double dx,double *results[])   {     int i;     for(i=0;i<N;i++)     {       *results[i]=(fwghost[i+2]-fwghost[i])/(2*dx);     }   } void secondc(int number,double fwghost[], double dx,double *results[])   {     int i;     for(i=0;i<N;i++)       {         *results[i]=(fwghost[i+2]+2*fwghost[i+1]-fwghost[i])/(dx*dx);       }   } int main( void )   {     int i,j;     double t[N+2],x[N+2],u_anal[N],u_ghost[N+2];     double v=5.;     FILE *fpout;     double dx=(xlast-xfirst)/(N-1);     double dt=(tlast-tfirst)/(M-1);     for(i=1;i<N+1;i++)       x[i]=xfirst+dx*i;     x[0]=x[1]-dx;     x[N+1]=x[N]+dx;     for(i=1;i<M+1;i++)       t[i]=tfirst+dt*i;     t[0] = t[1]-dt;     t[N+1] = t[N]+dt;     for(i=0;i<M;i++)       {         for(j=0;j<N;j++)           {             u_anal[j]=1/(1+exp((2*x[j+1]-t[i])/(4*v)));             printf("%0.2lf %0.15lf\n",x[j+1],u_anal[j]);           }       }     printf("analitikus lefutott.\n");     for(j=0;j<N+1;j++)       {         u_ghost[j]=1/(1+exp((2*x[j]-t[0])/(4*v)));       }     printf("u_ghost kész.\n");     fpout=fopen("burgers_anal.dat","w+");     if ( ! fpout)       {         printf("Cannot write file\n\n");         return 1;       }     for(j=0;j<N;j++)       {         fprintf(fpout,"%0.2lf %0.15lf\n",x[j+1],u_anal[j]);       }     fflush(fpout);     fclose(fpout);     return 0; }```
... it does work.