and debugger shows
Program received signal SIGSEGV, Segmentation fault.
0x0000003e45a6cc50 in _IO_new_file_fopen () from /lib64/libc.so.6
what i think is fopen should either return null pointer or a pointer to the file.its crashing doesn't really makes sense.code compiles well.
Code:
#include <stdio.h>
int main (int argc,char *arg[]){
printf("%d\n",argc);
if(argc!=3){
printf("usage smst <input terminal points file > <output file >\n this appliaction produces seprable mininmum spanning tree .\nit reads the input from tha input file \nand write the out put to the specified output file\n ");
exit(1);
}
FILE *f;
int *x,*y,n,i;
printf("opening file %s",arg[1]);
if((f=(FILE *)fopen(arg[1],'r'))==NULL) { // open a file
printf("could not open input file\n"); // print an error
exit(1);
}
fscanf("%d\n",&n);
x=(int*)malloc(sizeof(int)*n);
y=(int*)malloc(sizeof(int)*n);
for (i=0;i<n;i++){
fscanf(f,"%d\t%d\n",x+n,y+n);
printf("%d/t%d\n",x[n],y[n]);
}
fclose(f);
return 0;
}
can it be that the libraries are corrupt
if you try to run it,the program requires two parameter
one input file and one out put file.but that is not relevant because the program crashes at fopen. i have checked it via debugger.first input must be file to be opened and second input can be any file name or any thing