gpt4 book ai didi

未找到命令,后跟段错误 11

转载 作者:行者123 更新时间:2023-11-30 16:46:06 24 4
gpt4 key购买 nike

我试图制作一个可以获取类似输入的程序

   1     833N619DL  ABQ           26     204     214    1250
1 1125N660DL ABQ 18 211 204 1250
1 1589N678DL ABQ 23 206 212 1250
2 833N659DL ABQ 18 204 194 1250
2 1125N656DL ABQ 23 211 210 1250
2 1589N665DN ABQ 19 206 212 1250
3 833N686DA ABQ 23 204 204 1250
3 1125N692DL ABQ 27 211 216 1250
3 1589N635DL ABQ 26 206 210 1250
4 833N688DL ABQ 21 204 206 1250
4 1125N660DL ABQ 18 211 221 1250
4 1589N631DL ABQ 28 206 209 1250

此数据和输出仅输出输入中的数字(不包括数字和字母混合的列)

这是我的程序

#include <stdio.h>
#include <ctype.h>

#define MAXLINE 10000

char *itoa(int i); //convert integer to char array

main() {
int temp= 0, i = 0, c, j = 0;
char *a[MAXLINE]; //pointer array with uninitialized pointers

while((c = getchar()) != EOF)
if(isdigit(c))
temp = 10 * temp + c - '0';
else if(!isalpha(c)) {
a[i] = itoa(temp);
++i;

if(c == '\n') {
*a[i] = '\n';
j++;
}
}

printf("Data is\n");

for(int n = 0; n <= j; n++)
printf("%s\n", a[n]);
}

char *itoa(int i) {

char *s;

while(i % 10 != 0) {
*s++ = i / 10; //save to s
i = i % 10; //removed saved part from i
}

return s;
}

我编译了它并给出了上面的数据。我本应该按 control-D 告诉程序我已完成输入(EOF),但程序以段错误 11 响应,之后,终端开始接受我的输入,就好像我这样写:

urw7RS:Desktop urw7rseeh8fr$        1    1125N660DL  ABQ           18     211     204    1250

终端告诉我找不到该命令。这是输出:

urw7RS:Desktop urw7rseeh8fr$ ./a.out
1 833N619DL ABQ 26 204 214 1250
1 1125N660DL ABQ 18 211 204 1250
1 1589N678DL ABQ 23 206 212 1250
2 833N659DL ABQ 18 204 194 1250
2 1125N656DL ABQ 23 211 210 1250
2 1589N665DN ABQ 19 206 212 1250
3 833N686DA ABQ 23 204 204 1250
3 1125N692DL ABQ 27 211 216 1250
3 1589N635DL ABQ 26 206 210 1250
4 833N688DL ABQ 21 204 206 1250
4 1125N660DL ABQ 18 211 221 1250
4 1589N631DL ABQ 28 206 209 1250
Segmentation fault: 11
urw7RS:Desktop urw7rseeh8fr$ 1 1125N660DL ABQ 18 211 204 1250
-bash: 1: command not found
urw7RS:Desktop urw7rseeh8fr$ 1 1589N678DL ABQ 23 206 212 1250
-bash: 1: command not found
urw7RS:Desktop urw7rseeh8fr$ 2 833N659DL ABQ 18 204 194 1250
-bash: 2: command not found
urw7RS:Desktop urw7rseeh8fr$ 2 1125N656DL ABQ 23 211 210 1250
-bash: 2: command not found
urw7RS:Desktop urw7rseeh8fr$ 2 1589N665DN ABQ 19 206 212 1250
-bash: 2: command not found
urw7RS:Desktop urw7rseeh8fr$ 3 833N686DA ABQ 23 204 204 1250
-bash: 3: command not found
urw7RS:Desktop urw7rseeh8fr$ 3 1125N692DL ABQ 27 211 216 1250
-bash: 3: command not found
urw7RS:Desktop urw7rseeh8fr$ 3 1589N635DL ABQ 26 206 210 1250
-bash: 3: command not found
urw7RS:Desktop urw7rseeh8fr$ 4 833N688DL ABQ 21 204 206 1250
-bash: 4: command not found
urw7RS:Desktop urw7rseeh8fr$ 4 1125N660DL ABQ 18 211 221 1250
-bash: 4: command not found
urw7RS:Desktop urw7rseeh8fr$ 4 1589N631DL ABQ 28 206 209 1250
-bash: 4: command not found
urw7RS:Desktop urw7rseeh8fr$

我做错了什么?

最佳答案

看起来终端是解释你的数据而不是处理它,所以它尝试像命令一样执行每一行,并且不存在像你的每行开头的数字这样的命令文件。您确定正在执行您的程序而不是包含数据的文件吗?

此外,所有指向字符串的 char* 指针均未分配,因此您会遇到段错误

关于未找到命令,后跟段错误 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43874722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com