Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Separates and converts the numbers in a string into numbers, and then stores them in an integer array.
Separates and converts the numbers in a string into numbers, and then stores them in an integer array.
Write a function to handle CString variables, and use atoi to convert strings into integers when encountering spaces or' \ 0'!

Write more yourself!

I took the time to write it down, and it can run. The data is stored in nrt array, and the landlord can change it as needed!

Change ()

{

CString strtmp = " 24 22 33 43 56

char *ch,*chtmp,* chtmpf

int i=0,nrt[ 100];

ch = new char[ 100];

strcpy(ch,strtmp);

chtmp = ch

for(; ; )

{

chtmpf = chtmp

while (*chtmp! =“”& amp; & amp*chtmp! = '\0')

{

chtmp++;

}

if (*chtmp == '\0 ')

{

nrt[i++]= atoi(cht mpf);

Break;

}

* chtmp++ = ' \ 0 ';

nrt[i++]= atoi(cht mpf);

}

Delete [] ch;

}