我想從使用數組指針的文件中讀取兩行。但是,我沒有在屏幕上看到任何東西。我嘗試過在線搜索,但無法解決問題。這是我在Mac上使用Netbeans編寫的代碼。打印char指針數組
int main(int argc, char** argv) {
FILE *fp;
char *points[50];
char c;
int i=0;
fp=fopen("/Users/shubhamsharma/Desktop/data.txt","r");
if(fp==NULL)
{
printf("Reached here");
fprintf(stderr," Could not open the File!");
exit(1);
}
c=getc(fp);
while(c!=EOF)
{
*points[i]=c;
c=getc(fp);
i++;
}
for(int i=0;*points[i]!='\0';i++)
{
char d=*points[i];
printf("%c",d);
if(*(points[i+1])==',')
{
i=i+1;
}
}
return (EXIT_SUCCESS);
}
個人而言,我會使用一個調試器 –
'char * points [50]; char c;' - >'char points [50] = {0}; int c;' – BLUEPIXY
我試過,沒有使用指針,並工作。不過,我正在學習指針。因此,我必須有指針。 – Sankalps