-
-
Save dukenmarga/699e889fb1eeabad5f84902cfbcf45d2 to your computer and use it in GitHub Desktop.
Convert Character to Integer (C Language)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
char c[5] = "23452"; | |
char d[5] = "23452"; | |
int result=0, factor=3; | |
int numeric; | |
// take and convert 1 character from an array | |
numeric = c[2] - '0'; // --> 4 | |
result = factor*numeric; // result=12 | |
printf("Result : %d\n", result); | |
// convert array of char to int | |
numeric = atoi(d); // --> 23452 | |
result = factor*numeric; // result = 70356 | |
printf("Result : %d\n", result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment