返回信息流不知道为什么编译不了程序,谁能告诉下错误在哪里,谢谢。
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
bool fun(const char *s1, const char *s2){
return strcmp(s1, s2);
}
int main() {
char s[55][20];
int n;
while(scanf("%d",&n)==1&&n){
for(int i=0;i<n;i++)scanf("%s",s[i]);
sort(s, s+n, fun);
for(int i=0;i<n;i++)printf("%s\n",s[i]);
}
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #77235同步于 2014/3/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
请教一个编译问题
niania
2014/3/1镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
bool fun(const char *s1, const char *s2){
return strcmp(s1, s2);
}
int main() {
char *s[55];
int n;
while(scanf("%d",&n)==1&&n){
for(int i=0;i<n;i++){s[i]=new char[20];scanf("%s",s[i]); }
sort(s, s+n, fun);
for(int i=0;i<n;i++)printf("%s\n",s[i]);
}
return 0;
}
【 在 niania 的大作中提到: 】
: 不知道为什么编译不了程序,谁能告诉下错误在哪里,谢谢。
: #include<stdio.h>
: #include<algorithm>
: ...................
能具体说说为什么是那样的呢?
【 在 botieking 的大作中提到: 】
: #include<stdio.h>
: #include<algorithm>
: #include<cstring>
: ...................
char s[55][20];//表示字符的一个二维数组,然后你的程序scanf("%s",s[i]),s[i]是个啥?
【 在 niania 的大作中提到: 】
: 能具体说说为什么是那样的呢?
不能认为是i行的起始指针么?像一维那样?
【 在 botieking 的大作中提到: 】
: char s[55][20];//表示字符的一个二维数组,然后你的程序scanf("%s",s[i]),s[i]是个啥?
s[i] == &s[i][0] ?
我的编译器上没有问题。。。
【 在 botieking 的大作中提到: 】
: char s[55][20];//表示字符的一个二维数组,然后你的程序scanf("%s",s[i]),s[i]是个啥?
好的
【 在 zishi 的大作中提到: 】
: 是你sort的问题,你可以体会一下,char* s[55] 和 char s[55][20]在使用sort:特别是第二个参数 s+n 时候的区别