char c[6]="12345";
int d1,d2,d3,d4,d5;
d3=c[3];?????
如何把c[1],c[2],c[3]....单个取出来赋予d1,d2,d3,d4,d5呢
d1为1,d2为2,d3为3,d4为4,d5为5;
不要说d1=c[1]-0x30;这种方法.
还有方法越简单越好!越多越好

解决方案 »

  1.   

    char *pc;
    for(int i=0;i<5;i++)
      intTemp=atoi(pdc[i]);
      

  2.   

    char c[6]="12345";
    int d1,d2,d3;
    d1=atoi(c[1]);//行吗?
      

  3.   

    1 atoi是肯定可以的。
    2 d1=c[1]-'0'; 
      d2=c[2]-'0';  //这种方法为什么不可以用呀?我觉得挺好的。
      

  4.   

    d1=atoi(c[1]);//这种肯定不行
    d1=atoi(c);这样行
    我现在需要从c字符的某个字节取c[2]=2取出赋值给int d2;例:char c[17]="asdd123456asfdg";
    你们看如果是这样的一个字符窜我只能c[6],c[7]一个个的取值是吗?
      

  5.   

    将你要输出的字符作成一个字符数组
    用for循环/while/do_while都可以输出
    其他的基本已经搞定了!
    努力!
      

  6.   

    不要说d1=c[1]-0x30;这种方法.----怎么吃西瓜,---不能用嘴!
      

  7.   

    int n[6];
    for(int i=0;i<6;i++)
       n=a[i]-'0';
      

  8.   

    MSDN上的例子:
    #include <stdlib.h>
    #include <stdio.h>void main( void )
    {
       char *s; double x; int i; long l;   s = "  -2309.12E-15";    /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "7.8912654773d210";  /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "  -9885 pigs";      /* Test of atoi */
       i = atoi( s );
       printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );   s = "98854 dollars";     /* Test of atol */
       l = atol( s );
       printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
    }
    Outputatof test: ASCII string:   -2309.12E-15   float:  -2.309120e-012
    atof test: ASCII string: 7.8912654773d210   float:  7.891265e+210
    atoi test: ASCII string:   -9885 pigs      integer: -9885
    atol test: ASCII string: 98854 dollars      long: 98854
      

  9.   


    看样子只有这种丑陋的方法d1=c[1]-0x30;这种方法.
      

  10.   

    你说的是什么意思呀
    这么多人的回答都是错的吗?
    定义数组的时候是不是应该这样?
    int a[]={...}
    是多个用逗号隔开
    然后用atoi()什么的函数应该差不多了吧
    如果还不是
    发消息给我
    一个星期内回复