Reading long int using scanf

Betamoo picture Betamoo · May 17, 2010 · Viewed 96.2k times · Source

To read an int using scanf we use:

scanf("%d", &i);

What if i is a long not int??

Note: when using %d with long it gives me an irritating warning..

Answer

jpalecek picture jpalecek · May 17, 2010

Just use

long l;

scanf("%ld", &l);

it gives me an irritating warning..

That warning is quite right. This is begging for stack corruption.