请输入您要查询的百科知识:

 

词条 fgets
释义

§ 解释

函数名: fgets

功 能: 从流中读取一字符串

用 法: char *fgets(char *string, int n, FILE *stream);

§ 程序例

#include <string.h>

#include <stdio.h>

int main(void)

{

FILE *stream;

char string【】 = "This is a test";

char msg【20】;

/* open a file for update */

stream = fopen("DUMMY.FIL", "w+");

/* write a string into the file */

fwrite(string, strlen(string), 1, stream);

/* seek to the start of the file */

fseek(stream, 0, SEEK_SET);

/* read a string from the file */

fgets(msg, strlen(string)+1, stream);

/* display the string */

printf("%s", msg);

fclose(stream);

return 0;

}

随便看

 

百科全书收录594082条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2024/11/13 18:42:56