我有以下代码:
FILE *fpa;
fpa = fopen(argv[2], "r");
if (fpa == NULL) {
printf("Error: could not open seqA file!\n");
exit(0);
}
unsigned int N_a;
fscanf(fpa, "%d\n", &N_a);
char *seq_a = malloc((N_a+1) * sizeof(char *));
strcpy(seq_a,"");
fscanf(fpa, "%s\n", seq_a);
fclose(fpa);
for(i=0;i<N_a;i++)
printf("%s", seq_a[i]); ---> SEG FAULT
printf("\n");
我在 printf 语句中遇到分段错误。argv[2] 是一个文件,其内容为:
5
ABCBB
任何想法我可能会犯错误。