我很好奇,以前是否有人这样做过。如何从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