Hello everybody, I m a newbie and I m doing a code that the principal aim is to print a number if two strings are equal. First string is obtained from a file and the second one is the string to be compared with.
代码:
int main()
{
char *string[2];
FILE *stream;
stream = fopen("REL","r");
if( (stream = fopen("REL","r")) == NULL)
{
printf("Can t open %s
","REL");
exit(1);
}
for(int i=0;i<92;i++)
{
fscanf(stream,"%s",&string);
if( strcmp("20", *string) == 0 )
{
printf("%d",20);
}
}
fclose(stream);
}
当我在贝壳上做测试时, 它会加速我:
~/CM$ ./file2
Segmentation fault (core dumped)
我可能犯了一个愚蠢的错误,但是,作为一个新人,我不明白剧本出了什么问题。