发新话题
打印

关于字符数组和整型数组

关于字符数组和整型数组

请教大家一个问题怎么把指向字符数组的指针,转化成整型数组存储到一个指向整型数组的指针呢?比如
int *pres1;指向整型数组的指针;
char *pBuf1;指向字符型数组的指针;

int *pres1;
pres1=new int[x];
for(int m=0;m<x;m++)
{
    pres1=atoi(pBuf1);
}
请问各位高手知道怎么解决吗?
x是两个数组的大小

TOP

pres1=atoi(pBuf1);
这个好像有问题,pBuf1不是数组,是一个字符串的指针。

请看atoi的例子
Example

/* ATOF.C: This program shows how numbers stored
* as strings can be converted to numeric values
* using the atof, atoi, and atol functions.
*/

#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 );
}


Output

atof 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

TOP

这个例子看了很多遍了,但是用起来还是觉得很吃力,能不能给提示一下具体思路,就是具体怎么实现?

TOP

能不能搞的容易一点的啊

TOP

c++编译系统和数据库怎么连接啊

TOP

TOP

发新话题