Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to force a string to an integer in C language? For example, "162837" is converted to 162837
How to force a string to an integer in C language? For example, "162837" is converted to 162837

Use atoi function to convert. The header file is located in stdio.h.

Example reference:

#include

#include

char x[10] ={'1','6','2','8','3','7','\0'};

int main(void)

{

int y=atoi(x);

printf("This is a string.\n");

printf("%s\ n", x);

printf("This is a number.\n");

printf("%d\n", y);

< p> system("pause");

return 0;

}