fscanf - segmentation fault (core dumped) in C

Was trying to write a little program when faced a problem that has never occured to me before. There seems to be a segmentation fault in fscanf function, though can't really figure the problem out. Here's my code:

#include <stdio.h>

int main(){
    FILE *fin = ("file.in", "r");
    int n, t;
    fscanf(fin, "%d %d", &n, &t);
    return 0;
}

And the file.in:

3 19

Hope you have some ideas. Any help appreciated! Rugile :)

Answers


Uninitialized variables FILE *fin = ("file.in", "r"); - cause Undefined behaviors.

FILE *fin = fopen ("file.in", "r");

It compiles because ("file.in", "r") evaluates to "r" due to Comma operator effect.


FILE *fin = fopen ("file.in", "r");

If doing like FILE *fin = ("file.in", "r");

GCC Reports:

warning: initialization from incompatible pointer type [enabled by default]

Need Your Help

Durandal Get Started Sample

durandal durandal-2.0

I've tried following the Get Started example from the Durandal homepage, and just get..

Browser automate tasks

jquery python google-chrome

So I am watching some videos on a webpage where there is a playlist. The problem with the playlist is that it doesnt "auto-play". SO everytime one video ends I have to manually go to the playlist and