-1
我用这段代码不断收到段错误,我试图打印字典的前6个单词。我敢肯定,我使用的fscanf错误,但我不知道如何/为什么...Fscanf Seg Fault
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
int main(int argc, char* enc[])
{
if (argc != 2)
{
printf("Improper command-line arguments\n");
return 1;
}
FILE *Dict;
Dict = fopen("/usr/share/dict/words", "r");
if (Dict == NULL)
{
printf("Could not open dictionary");
exit(1);
}
char* full = enc[1];
char* salt[2];
for (int i=0; i<2; i++)
{
salt[i] = &full[i];
}
char* key[50];
for (int i=0; i<6; i++)
{
fscanf(Dict, "%s", *key);
printf("%s", *key);
}
}
你叫什么题? “这是一段代码,猜猜它应该做什么并为我调试”不是问题。 – Adam
它应该打印字典的前6个单词。最后,我在for循环中遇到了问题,它导致了分段错误。 – user3303819
精益如何使用IDE的调试器。看看这一行 - fscanf(Dict,“%s”,* key); – OldProgrammer