本帖最后由 jiangenhao 于 2014-4-21 22:22 编辑
- 把字符串按单词存放到一个二位数组中 不知道哪里出错了
- #include <stdio.h>
- #include <string.h>
- int main ()
- {
- char a[1000] = "welcome to china beijing is the capital of china you isnot a true man if didnot went to changcheng enjoy your journey";
- printf("%s\n",a);
-
- // for(int k = 0,k < 1000,k++)
- // {
- // char b [i][j] = char a [k];
- // }
-
- char b[100][10];
- for(int k = 0;k < 1000;k++)
- {
- for(int i = 0;i<100;i++)
- {
- for(int j =0;j<10;j++)
- {
-
- if(a[k]==' ')
- {
- break;
- }
- b[i][j] = a[k];
- }
-
- }
- }
- for(int i =0;i<100;i++)
- {
- for(int j=0;j<10;j++)
- {
- printf("%c",b[i][j]);
- }
- printf("\n");
- }
-
- return 0;
- }
复制代码
|