我很好奇,以前是否有人這樣做過。如何從C中的結構中獲取字符串?
我遇到了從結構中獲取字符串的問題。我想要做的是從我正在使用的特定結構中獲取字符串,然後將該字符串放入fprintf(「%s」,whateverstring)中;
FILE* outfile = fopen("Z:\\NH\\instructions.txt","wb");
if ((dir = opendir ("Z:\\NH\\sqltesting\\")) != NULL) {// open directory and if it exists
while ((ent = readdir (dir)) != NULL) { //while the directory isn't null
printf("%s\n", ent->d_name); //I can do THIS okay
fprintf("%s\n",ent->d_name); //but I can't do this
fclose(outfile);
}
}
closedir (dir);
//else {
//
// perror (""); //print error and panic
// return EXIT_FAILURE;
//}
}
我在這裏採取了錯誤的做法?我以某種方式考慮使用類似char[80] =ent.d_name;
但顯然不起作用。有什麼方法可以從結構中獲取該字符串並將其放入fprintf中?
heh?你讀過手冊頁嗎? –
另外,沒有關於結構的信息。 – sjsam
['fprintf()'](http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html)不會將格式字符串作爲第一個參數。 – dhke