Mega Code Archive

 
Categories / C / Code Snippets
 

Converts the string to an int value

//Declaration: int atoi(const char *str); #include <stdlib.h> #include <stdio.h> int main(void) { char j1[80], j2[80]; printf("Enter first: "); gets(j1); printf("Enter second: "); gets(j2); printf("The sum is: %d.", atoi(j1)+atoi(j2)); return 0; } /* Enter first: 3 Enter second: 4 The sum is: 7.*/