#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#undef EOF
#define EOF -1
#define N 20
/*
函数fun,该函数的功能是:将放在字符串数组中的m个字符串(每串的长度不超过n),按顺序合并组成一个新的字符串。
*/
void fun(char s[N][N],int mi);
int main(int argc,char *argv[])
{
int i,m,j;
char str[N][N]={0};
printf("Please input the number of string : ");
scanf("%d",&m);
printf("Please input the strings \n");
for(i=0;i<m;i++)
{
printf("Please input the %d words :",i+1);
gets(str[i]); //可以这样存入字符串,为什么?
}
/*
for(i=0;i<N;++i)
{
for(j=0;j<N;++j)
{
printf("%c ",str[i][j]);
}
printf("\n");
}
*/
fun(str,m);
system("pause");
return 0;
}
void fun(char s[N][N],int mi)
{
int cmp;
char tmp[N];
int i,j;
for(i=0;i<mi-1;i++)
{
for(j=0;jg;j++)
{
cmp=strcmp(s[j],s[j+1]);
if(cmp>0)
{
strcpy(tmp,s[j]);
strcpy(s[j],s[j+1]);
strcpy(s[j+1],tmp);
}
}
}
for(i=0;i<mi;i++)
{
puts(s[i]);
}
}
不知道进一步学习能不能解决这个问题,感觉就是很疑惑,不太明白这种存储机制,
一个疑惑,为什么在二维数组里可以自动换行存入字符串,以及冒泡的趟数问题?
最新推荐文章于 2020-10-15 20:37:30 发布