#include <stdio.h>
int main(){
int m=0, n=0, max=0;
char ch;
char arr[1024][1024];
printf("请输入一个英文句子:");
while(1){
ch = getchar();
if(ch == '\n') break;
else if(ch == ' '){
max = (max >= (n+1) ? max : n+1);
m++; n=0;
}
else arr[m][n++] = ch;
}
max = (max >= (n+1) ? max : n+1);
char res[m+1][max];
for(int i=0; i<=m; i++){
for(int j=0; j<max; j++){
if(arr[i][j]) res[i][j] = arr[i][j];
else res[i][j] = '\0';
}
}
printf("分割结果已存放到result[%d][%d]的二维数组中...\n现在依次打印每个单词:\n", m+1, max);
for (int i=0; i<=m; i++){
for(int j=0; j<max; j++) printf("%c", res[i][j]);
printf("\n");
}
return 0;
}
请输入一个英文句子:asd asd sdf; lsdfk
分割结果已存放到result[4][6]的二维数组中...
现在依次打印每个单词:
asd
asd
sdf;
lsdfk
|