char s[5] = "5:25"; 
int     t[4];
 
for(int i=0,j=0;i<5;i++)
if(i!=1)
{
t[j]=atoi(&s[i]);
j++;
}

解决方案 »

  1.   

    下面的程序已调试成功,用吧
    #include <stdlib.h>
    int fun()
    {
    char s[] = "6565:25";      /* Test of atoi */
    int     t[2];        //////存放转换后的数据
    int j=0 ;
    for(int i=0;i<3;i++)
    if(i!=1)          
    {
    t[j]=atoi(&s[i]);j++;
    }printf( "atoi test: ASCII string: %s\t\tinteger: %d    %d\n", s,t[0],t[1] );
    getchar();
    getchar();return 0;
    }
      

  2.   

    the correct way is: split the CString to sub CString , "5:25" should be split into "5" and "25",then change it to number! 
      

  3.   

    对于任何形式的"aaaa:bb"可以用以下方法获取整形数aaaa,和bb,如下面的例子:
    CString str,str1,str2;
    str="4885:25";
    int nCount=str.GetLength();
    int pos=str.Find(":");
    str1=str.Left(pos);
    str2=str.Right(nCount-pos-1);
    int a,b;
    a=::atoi(str1);
    b=::atoi(str2);
      

  4.   

    闲了没事,调试出更好的,很好用哦
    const char s[] = "5sdd546gfd:2455";   //   Test of atoi 
    int    t[20];        //////存放要提取的数据
    int j=0,b ;
    bool prvo=false;         ///判断是否前面的字符是数字的标志
    char ss[2]={'a','e'};b=sizeof(s);
    /////////
    for(int i=0;i<b;i++)
    if(s[i]<='9'&&s[i]>='0')          //如果是数字则转换
    {
    if(prvo==false)
    {
              t[j]=atoi(&s[i]);
             j++;
     prvo=true;
    }
    }
    else
      prvo=false;
    printf( "\natoi test: ASCII string: %s \n", s );
    for(i=0;i<j;i++)
      printf("%d   ",t[i]);