C语言怎样循环创建数组

比如我要创建100个数组,不用二维数组的方法

#include <stdio.h>
#include<stdlib.h>
struct s
{int a[2];
struct s *next;
}; //定义了一个结构体
main()
{ int i=0;
struct s *head,*p;
head=p=(struct s *)malloc(sizeof(struct s));//开辟一个新单元
for(i=0;i<2;i++) //定i<2,(如果你想要100个数组,i 就等于100)类似于你定义了2个一维数组
{
scanf("%d",p->a);
p=p->next=(struct s *)malloc(sizeof(struct s));
}
p=head;//使p指针指向第一个数组
printf("%d\n",p->a[0]);//如果你想看第二个数组里的a[0]的数值改成(p->a[0])+1。
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-31
可以使用malloc开一个临时空间,返回的值即为数组头地址。
第2个回答  2013-07-31
#define count 100
int* p[count];
for(int i=0;i<count;i++)
{
p[i]=new int[100];
}

这样算不用二维了吧