第1个回答 2015-10-23
程序写错了,指针所指的位置不对,改成这样:
void main()
{
int N=3;
char str0[3][20],*p,*q; ;
q=str0[0];
printf("please write %d string:\n",N);
for(p=q;p<q+N*20;p+=20) gets(p);
for(p=q;p<q+N*20;p+=20) puts(p);
system("pause");
return;
}
这样写的程序最多接受3个字符串,每个字符串最大长度为20,不如使用c++里的vector和string,多大多长都可以
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void main()
{
int N=3; //N可以为任意值
vector<string> vec;
string temp;
printf("please write %d string:\n",N);
for(int i=0;i<N;i++){cin>>temp;vec.push_back(temp);}
for(int i=0;i<N;i++) cout<<vec[i]<<endl;
system("pause");
return;
}本回答被提问者采纳