###### 问题遇到的现象和发生背景
创建用户库strpro.h和openfile.h,其中strpro.h中包含getString、sort和read函数,而openfile.h中包含openw函数。
在main函数中提示用户输入一句英文句子,要求:
###### 问题相关代码,请勿粘贴截图
#include <stdio.h>
#include "strpro.h"
int main()
{
char word[15][15];
getString (word);
sort (word);
print(word);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void print(char word[][15])
{
int i;
for (i=0;i<15;i++)
{
printf("%s",word[i][15]);
}
}
//Here, we are reading the data.
void getString(char word[][15])
{
printf("\nPlease input an English sentence: \n");
char c;
int i=0,j=0;
do
{
scanf("%c",&word[i][j]);
if ( word[i][j] == ' ')
{
word[i][j] = '\0'; //It means a word.
i++;
j = 0;
}
else if ( word[i][j] == '\n' || word[i][j] == '.') //The entering is end.
{
word[i][j] = '\0';
break;
}
else if (isalpha(word[i][j]))
{
j++;
}
} while (1);
putchar('c');
}
//Here is the Buddle.
int sort(char word[][15])
{
int a,b;
char temp;
for (a=14;a>0;a--)
{
for (b=0;b<15;b++)
{
if (strcmp(word[b][15],word[b+1][15]))
{
temp = word[b][15];
word[b][15] = word[b+1][15];
word[b+1][15] = temp;
}
}
}
return 0;
}
void read()
{
}
###### 运行结果及报错内容
char array[10][10]
array[m][n]代表的是字符,而不是字符串
我写的程序真是错漏百出唉,又发现了字符串的赋值应该用strcpy