Segmentation fault when using files C++
Posted
by
Popa Mihai
on Stack Overflow
See other posts from Stack Overflow
or by Popa Mihai
Published on 2012-09-10T15:27:48Z
Indexed on
2012/09/10
15:38 UTC
Read the original article
Hit count: 194
I am using ubuntu 12.04. I have been trying a few IDE's for simple C++ school projects. However, with codelite, anjuta and kdevelop I encountered a problem: when I am trying to read / write in files I get segmentation fault: core dumped.
I am using a basic source:
#include<stdio.h>
FILE*f=fopen("test.in","r");
FILE*g=fopen("test.out","w");
int main () {
int a,b;
fscanf(f,"%d %d",&a,&b);
fprintf(g,"%d\n",a+b);
fclose(f);
fclose(g);
return 0;
}
I have to say that programs with stdin/stdout work well.
Thank you,
© Stack Overflow or respective owner