Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用fgetc读取文件_C_Function_Fgetc - Fatal编程技术网

如何使用fgetc读取文件

如何使用fgetc读取文件,c,function,fgetc,C,Function,Fgetc,很抱歉,这个问题不是很清楚,我到目前为止的代码如下所示,我只是停留在如何使用while循环打印文件内容上 #include<stdio.h> int main() { FILE *number; /* Open the file 'numbers' for reading */ number = fopen("numbers.dat", "r"); if (number != NULL) { /* A bit of space for a line of text */

很抱歉,这个问题不是很清楚,我到目前为止的代码如下所示,我只是停留在如何使用while循环打印文件内容上

#include<stdio.h>


int main()
{
FILE *number;


/* Open the file 'numbers' for reading */
number = fopen("numbers.dat", "r");

if (number != NULL) {
/* A bit of space for a line of text */

char lineOfText[100];
while (fgetc(lineOfText, 100, number) != NULL) {
printf("%s\n", lineOfText);
}
   fclose(number);
}
 /* sorry, my question was not clear and to clarify i am trying to 
Print out the contents of the file with one entry per line, my .dat file includes 
1,2,3,4,5,6,7,8,9 and i am trying to print them out in this format
1
2
3
4 and so on...

*/
#包括
int main()
{
档案*编号;
/*打开文件“number”进行读取*/
数字=fopen(“数字.dat”,“r”);
如果(数字!=NULL){
/*为一行文本留出一点空间*/
字符行文本[100];
while(fgetc(lineOfText,100,number)!=NULL){
printf(“%s\n”,文本行);
}
fclose(数字);
}
/*对不起,我的问题不清楚,为了澄清我正在努力
打印文件内容,每行一个条目,my.dat文件包括
1,2,3,4,5,6,7,8,9我正试图用这种格式打印出来
1.
2.
3.
4等等。。。
*/
让您开始

FILE * f;
int c;  
f=fopen ("numbers.txt","r");    
while((c = fgetc(f)) != EOF) printf("%c", isdigit(c)? c : ' ');     
fclose (f);

你试过什么?请展示你的代码。到目前为止你做了什么?现在又做了什么?“我想要”不是一个问题。这里有一个想法:先试试,不要按OP的要求去做。特例“6”在哪里处理?(但我会接受答案“留给OP作为家庭作业”。)@Jongware很难从他问自己的实际意思中分辨出来,文件是123456,他想要123456,还是文件是123456,他想要123456,或者文件是123456,他想要123456,或者文件是123456,或者文件是123456,他想要123456,或者他想要123456,或者他想要123456,或者他是否想要删除6。然而,这个主题的主要问题是如何一次读取一个字符,他有一个这样的例子,所以他可以工作知道如何让它做他想做的事是的,“问代码的问题”等等。这一个应该关闭-@jimmcnamara在第一个评论中就说对了。