0
我试图逐个检查字符,所以我需要在我的2D数组中一次访问一个字符。我试图使用双指针(例如:**p
),但我的程序只是崩溃。所以我使用*p
,但它给了我垃圾。在2D数组中一次只能访问一个字符
这里是我的代码:
FILE *in;
in = fopen("thefiles.txt", "r");
if (!in) {
printf("Failed to open input file\n");
exit(1);
}
int j;
char phrase[N_STRINGS][MAX_LENGTH_OF_A_SINGLE_STRING];
char string[MAX_LENGTH_OF_A_SINGLE_STRING];
for(j = 0; j < N_STRINGS; j++)
{
fscanf(in, "%s", string);
strcpy(phrase[j], string);
}
char *p;
*p = phrase[0][0];
// Trying to use a pointer to point at the beginning(?) of the array
printf("P = %s", p);
// After printing it out, I see that it gives me rubbish
谢谢了!
编辑:
好的,我想我刚刚解决了我自己的问题。哈! 所有我需要的是:
char p = phrase[0][0];
不应该有摆在首位指针搞砸:P
我在这段代码的其他地方看不到'word'? – RussS 2012-02-03 02:09:03
变量'word'是什么?你的意思是使用'词组'吗?你没有给'p'赋值。 – 2012-02-03 02:09:48
是的,抱歉。词应该是短语。让我编辑它:) – Dino55 2012-02-03 03:02:10