Three problems here. First
scanf(ifp,"%lf %lf\n",&theta,&Cla);
You’re calling scanf
when you look like you want to use fscanf
:
fscanf(ifp,"%lf %lf\n",&theta,&Cla);
Second is the file you’re opening:
ifp=fopen(argv[0],"r");
argv[0]
is the name of the running executable, which is probably not what you want. If you want the first argument passed in, use argv[1]
ifp=fopen(argv[1],"r");
Last is the definition of main
:
double main( char *argv[]){
This is not a valid definition, as it should return an int
and have both argc
and argv
or neither of them:
int main( int argc, char *argv[]){
You should also check that an argument was passed:
if (argc < 2) {
printf("missing argument\n");
exit(1);
}
1
solved Segmentation fault using scanf() [closed]