LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using fgets/sscanf wiht c (https://www.linuxquestions.org/questions/programming-9/using-fgets-sscanf-wiht-c-422110/)

true_atlantis 03-06-2006 06:36 AM

using fgets/sscanf wiht c
 
im having trouble trying to get fgets and sscanf to work. im getting a segmentation fault right at the sscanf line of this code... can anyone tell me the reason?


Code:

int main() {
        int integ;
        char line[400];

        printf("Enter an integer: ");
        fgets(line, sizeof(line), stdin);
        sscanf(line,"%d",&integ);
        printf("%d",&integ);
        return 0;
}



NEVERMID, FOUND MY PROBLEM, PLEASE REMOVE!!

msyss 03-06-2006 08:09 AM

That's weird. I compiled it on my machine, and it works.

Could you tell which compiler you are using?

paulsm4 03-06-2006 12:15 PM

So what was the problem (besides the "&integ" in your "printf()" - which *shouldn't* cause a segv)?


All times are GMT -5. The time now is 12:35 PM.