segmentation fault

Asked by Vikram Dhillon

       Alright so I need a program to run for a class, and I am using Ubuntu 9.04 default installation with GCC 4.33 and I am trying to compile a program, it is as follows:

#include <stdio.h>

#define PI 3.1415926535898

int main() {

    FILE *ifp;
    int numcases;
    int day;
    int mph, time;
    double radius;
    double area;

    ifp = fopen("jetski.in", "r");

    fscanf(ifp, "%d", &numcases);

    for (day=1; day<=numcases; day++) {

       fscanf(ifp,"%d%d", &mph, &time);
       radius = mph*time/60.0;
       area = .5*PI*radius*radius;

       printf("Day %d: %.2lf\n", day, area);
    }

    fclose(ifp);
    return 0;
}

Really simple program that takes in values and gives out some, but after compiling it with "gcc test.c" it gives me a file a.out and when I do "./a.out" it gives me error saying segmentation fault, even when I try "sudo su" One more question is there any program that can convert the code in c and c++ to be used in Linux. I have more than 4000 lines of coding in adaboost project that I need to be able to use in linux so please help. I don't use MATLAB because it is slower so please please help me out here... I am kind of stuck

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Vikram Dhillon
Solved:
Last query:
Last reply:
Revision history for this message
Vikram Dhillon (dhillon-v10) said :
#1

never mind its solved

Revision history for this message
Vikram Dhillon (dhillon-v10) said :
#2

I just messed up a little bit on the compiling part.. sorry

Revision history for this message
Vikram Dhillon (dhillon-v10) said :
#3

I just messed up a little bit on the compiling part.. sorry

Revision history for this message
DrEddy (bremby) said :
#4

Hi Vikram, it seems I'm having similar problem, what was your problem?

My problem is that whenever I do:
f = fopen("whatever", "r");
the program crashes with Segmentation fault.

So what was on your side?