Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Ask questions about converting string arrays into plastic arrays.
Ask questions about converting string arrays into plastic arrays.
Assuming that the characters in the string array are numbers (signed is allowed) and the numerical range is within the range allowed by int, you can use sscanf ().

Program example:

# include & ltstdio.h & gt

int main(){

char s[3][ 10]= { "+ 123 ","-4567 "," 98765432 1 " };

int a[3]; //store the results

int I;

for(I = 0; I<3; i++) sscanf(s[i]," %d ",& ampa[I]);

for(I = 0; I<3; i++) printf("%d\n ",a[I]);

Returns 0;

}

Output result:

123

-4567

98765432 1

===

If it is a simple numeric string, convert it to a number, consider the ASCII value, and use the following methods:

# include & ltstdio.h & gt

int main(){

char S2[80]= { " 123456700098765432 1 " };

int a2[80];

int i,n;

n = strlen(S2);

for(I = 0; I & ltn;; i++)a2[I]= S2[I]--0; //In this way

for(I = 0; I & ltn;; i++)printf("%d\n ",a2[I]);

Returns 0;

}