Segmentation fault using scanf() [closed]

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:


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]


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");

Browse More Popular Posts

Leave a Comment