
能写函数,能调用函数,能运行,没输出,有没有人写一下给个思路,写了好久了,按照要求写那4个函数并调用
一个实现如下:
参考链接:
https://www.cnblogs.com/990924991101ywg/p/10771972.html
c语言strcpy()用法-CSDN博客
文章浏览阅读10w+次,点赞114次,收藏347次。c语言strcpy()用法strcpy,即string copy(字符串复制)的缩写。strcpy是一种C语言的标准库函数,strcpy把从src地址开始且含有’\0’结束符的字符串复制到以dest开始的地址空间,返回值的类型为char*。通俗解释定义一个字符串char a[20],和一个字符串c[]=“i am a teacher!”;把c复制到a中就可以这样用:strcpy(a,c)..._strcpy
https://blog.csdn.net/mao_hui_fei/article/details/84642447
#include <stdio.h>
#include <string.h>
#define M 100
#define N 80
void inputarr(char array[][N],int n);
void sortstr(char array[][N],int n);
void outputarr(char array[][N],int n);
void swap(char *p1,char *p2);
int main(void){
char array[M][N];
int n;
scanf("%d",&n);
inputarr(array,n);
sortstr(array,n);
outputarr(array,n);
}
void inputarr(char array[][N],int n){
for(int i=0;i<n;i++){
scanf("%s",array[i]); // 从输入获取一个字符串,存入二维数组array当前下标元素中
}
}
void sortstr(char array[][N],int n){
// 按照字符串的ASCII码从小到大排序二维数组中的字符串
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
// https://www.cnblogs.com/990924991101ywg/p/10771972.html
if(strcmp(array[i],array[j])>0){
swap(array[i],array[j]);
}
}
}
}
void outputarr(char array[][N],int n){
// 打印二维字符数组中存储的字符串,每行一个
for(int i=0;i<n;i++){
printf("%s\n",array[i]);
}
}
void swap(char *p1,char *p2){
// https://blog.csdn.net/mao_hui_fei/article/details/84642447
// 交换字符指针p1里的字符串和字符指针p2中的字符串
char temp[N];
strcpy(temp,p1);
strcpy(p1,p2);
strcpy(p2,temp);
}
