c++oj报错为Segmentation Fault,请问大佬哪里错了

qq_45733343 2020-02-02 02:01:58

报错为Segmentation Fault

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
char passage[1005][20];
char me[100] = "zfacmilan";
int flag = 0,count=0;
for (int i=0;;i++) {
count++;
for (int j = 0;;j++) {
char c = getchar();
if (c == EOF) {
flag = 1;
break;
}
else if (!((c>='a' && c<= 'z') || (c>= 'A' && c <= 'Z'))) {
flag == 0;
break;
}
else {
passage[i][j] = c;
}
}
if (flag == 1)break;
}
int num;
cin >> num;
char name[1000][100] = {};
for (int i = 0;i < num;i++) {
cin >> name[i];
}
int nop[1000] = {};
for (int i = 0;i < num;i++) {
for (int j = 0;j < count;j++) {
if (strcmp(name[i], passage[j]) == 0) {
nop[i]++;
}
}
}
int menum = 0;
for (int j = 0;j < count;j++) {
if (strcmp(me, passage[j]) == 0) {
menum++;
}
}
int max=nop[0],whatnum=0;
for (int i = 0;i < num;i++) {
if (max < nop[i]) {
max = nop[i];
whatnum = i;
}
}
cout << name[whatnum] <<" "<< max << endl;
cout << me <<" "<< menum << endl;
return 0;
}
报错为Segmentation Fault
...全文
467 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
寻开心 2020-02-02
  • 打赏
  • 举报
回复
else if (!((c>='a' && c<= 'z') || (c>= 'A' && c <= 'Z'))) {
flag == 0; // 这里多个=号吧
break;
}


char name[1000][100] ; // 这种大的数组, 做成全局变量, 不要做成局部变量, 栈大小容纳不下就会爆


不知道你要实现的目的是什么, 最好附带上原始题目要求

33,322

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧