正在加载图片...
#include<stdio. h> maino FILE fp char str[11]; if(fp= - fopen("e: name. txt","r")=NULL)/*以只读方式打开 name. txt文件* printi("n无法打开文件 name. txt!mn") exit(l) fgets(str, 11, fp); /*从文件 string中读取10个字符放入字符串str中 printf("从 name. txt文件中读出的字符为:hn") printf("\n%s\n", str) /*在屏幕上输出字符串str* fclose(fp) 关闭文件*#include<stdio.h> main() { FILE*fp; char str[11]; if((fp=fopen("e:\\name.txt","r"))==NULL) /*以只读方式打开 name.txt 文件*/ { printf("\n 无法打开文件 name.txt!\n"); exit(1); } fgets(str,11,fp); /*从文件 string 中读取 10 个字符,放入字符串 str 中*/ printf("从 name.txt 文件中读出的字符为:\n"); printf("\n%s\n",str); /*在屏幕上输出字符串 str*/ fclose(fp); /*关闭文件*/ }
©2008-现在 cucdc.com 高等教育资讯网 版权所有