从文件中读取一个字符串 [英] reading a string from a file
本文介绍了从文件中读取一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件。我要读从文本文件中的一个字符串。我正在使用C code。任何机构可以帮助?
I have one text file. I have to read one string from the text file. I am using c code. can any body help ?
推荐答案
使用与fgets
来从文件中读取字符串中的 C
Use fgets
to read string from files in C.
是这样的:
#include <stdio.h>
#define BUZZ_SIZE 1024
int main(int argc, char **argv)
{
char buff[BUZZ_SIZE];
FILE *f = fopen("f.txt", "r");
fgets(buff, BUZZ_SIZE, f);
printf("String read: %s\n", buff);
fclose(f);
return 0;
}
避免了简单
安全检查。
Security checks avoided for simplicity.
这篇关于从文件中读取一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文