Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The value of variable a is string type 2, how to convert it to integer type
The value of variable a is string type 2, how to convert it to integer type

Use sscanf to convert:

#include

int main(){

int a;

char s[]="2";

sscanf(s,"%d",&a); //The reading format is converted to integer using %d

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

return 0;

}

Output integer value 2