我在运行下面的程序时遇到了这个问题。一切都编译得很好,但是当我运行它并输入一些东西时,我收到了段错误消息。它不是完整的代码,只是其中的一部分,它应该将输入文件中的一些字符串(地址)写入字符串数组,然后在数组中找到搜索字符串(作为参数输入)的可能匹配项。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *entry1 = argv[1], *adress[100], *possibleAdress[100], c;
int i,j,k,possible = 0;
while(c = getchar()!=EOF) //write addresses to array
{
while(c = getchar()!=13)
{
adress[i][j] = c;
j++;
}
i++;
}
i = 0;
while(adress[i]!=0) //find adresses matching with search enrty
{
j = 0;
while(adress[i][j]!=0)
{
while(entry1[j]==adress[i][j])
j++;
if(j==strlen(entry1)) //check if the whole search entry is matching
{
possibleAdress[k] = adress[i];
k++;
}
i++;
}
}
return 0;
}
最佳答案
我可以清楚地看到不正确的一件事是,在 while 循环中使用之前,您没有在 main 中初始化 i 和 j 的值。
关于c - 我该如何处理 "segmentation fault(core dumped)"错误?(没有在其他地方找到答案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46778427/