最新的网络安全咨询!

〓.::展翅高飞::.〓

指针数组的运用

3月 13th, 2008 by XSign

如果过有如下定义:

char *s[2];

那么可以用如下方式对这个指针数组进行操作:

#include<stdio.h>
#include<string.h>

int main(int argc,char *argv[])
{
 char *s[2];
 int i;

 for(i=0;i<2;i++)
  s[i]=new char[2];
 
 for(i=0;i<2;i++)
  gets(s[i]);

 for(i=0;i<2;i++)
  printf(”%s\n”,s[i]);

 return 0;
}

不能用gets(szBuf)直接对该数组进行操作,因为还没有为该指针分配内存地址!

详见http://topic.csdn.net/u/20080313/17/cc32ed09-0ba1-459c-a21c-cb5ebfda1b43.html

Filed under C/C++, .::编程心得::. having

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.