Mega Code Archive

 
Categories / C / Code Snippets
 

Convert string to long integer how to use strtol

#include <stdio.h> #include <stdlib.h> int main () { char str[256]; char *p; long j; printf ("Enter an long value: "); gets (str); j = strtol (str, &p, 0); printf ("Value entered: %ld. Its double: %ld\n", j, j * 2); return 0; }