C语言如何读取txt文本里面的内容?C语言可以使用fopen()函数读取txt文本里 。
示例C语言是文本内容函数:
#include stdio.h
FILE *stream, *stream2;
void main( void )
{
int numclosed;
/* Open for read (will fail if file "data" does not exist) */
if( (stream= fopen( "data", "r" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" );
/* Open for write */
if( (stream2 = fopen( "data2", "w+" )) == NULL )
printf( "The file 'data2' was not opened\n" );
else
printf( "The file 'data2' was opened\n" );
/* Close stream */
if(fclose( stream2 ))
printf( "The file 'data2' was not closed\n" );
/* All other files are closed: */
numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
扩展资料
使用fgetc函数
#include stdio.h
#include stdlib.h
void main( void )
{
FILE *stream;
char buffer[81];
inti, ch;
/* Open file to read line from: */
if( (stream = fopen( "fgetc.c", "r" )) == NULL )
exit( 0 );
/* Read in first 80 characters and place them in "buffer": */
ch = fgetc( stream );
for( i=0; (i80 )( feof( stream ) == 0 ); i++ )
{
buffer[i] = (char)ch;
ch = fgetc( stream );
}
/* Add null to end string */
buffer[i] = '\0';
printf( "%s\n", buffer );
fclose( stream );
}
关于C语言是文本内容函数和c语言是文本内容函数嘛的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 自走棋日本服务器,dota2自走棋服务器日本
- u盘怎么连手机,惠普u盘怎么连手机
- word怎么把表格压缩,word表格怎么压缩行距
- fx777a显卡怎么样,fx770显卡
- java源代码风险漏洞 java代码漏洞扫描
- 华硕pg279q安装方法,华硕pg279vq
- python开发试卷,python卷子
- 月份怎么加减mysql 月份怎么加减
- mysql查找替换字符,mysql替换某个字段的某个字符串