
c语言的小问题,在线等候,高分悬赏
Writeaprogramthatopensatextfilewhosenameisobtainedinteractively.Setupaloopthatasksthe...
Write a program that opens a text file whose name is obtained interactively. Set up a loop that
asks the user to enter a file position. The program then should print the part of the file starting
at that position and proceed to the next newline character. Let nonnumeric input terminate
the user-input loop.
不是翻译
而是编程序
请大家注意
无比完全运行了给我
VC++
实在是是走投无路了 展开
asks the user to enter a file position. The program then should print the part of the file starting
at that position and proceed to the next newline character. Let nonnumeric input terminate
the user-input loop.
不是翻译
而是编程序
请大家注意
无比完全运行了给我
VC++
实在是是走投无路了 展开
4个回答
展开全部
#include <stdio.h>
int main(void)
{
char fname[256]; /* 文件名 */
int pos; /* 文件位置 */
int ch; /* 读入字符 */
FILE *fp; /* 文件指针 */
printf("filename: ");
gets(fname); /* 读取文件名 */
fp=fopen(fname,"r"); /* 打开文件 */
/* 文件不存在 */
if(fp==NULL)
{
printf("can't find %s\n",fname);
return 0;
}
/* 查询文本 */
while(1)
{
printf("position: ");
if(!scanf("%d",&pos)) break; /* 输入非法字符 */
rewind(fp); /* 清空键盘缓冲区 */
fseek(fp,pos,SEEK_SET); /* 跳到指定位置 */
do
{
ch=fgetc(fp); /* 读入字符 */
if(ch!=EOF) putchar(ch); /* 输出字符 */
}while(ch!='\n'&&ch!=EOF);
}
fclose(fp); /* 关闭文件 */
return 0;
}
int main(void)
{
char fname[256]; /* 文件名 */
int pos; /* 文件位置 */
int ch; /* 读入字符 */
FILE *fp; /* 文件指针 */
printf("filename: ");
gets(fname); /* 读取文件名 */
fp=fopen(fname,"r"); /* 打开文件 */
/* 文件不存在 */
if(fp==NULL)
{
printf("can't find %s\n",fname);
return 0;
}
/* 查询文本 */
while(1)
{
printf("position: ");
if(!scanf("%d",&pos)) break; /* 输入非法字符 */
rewind(fp); /* 清空键盘缓冲区 */
fseek(fp,pos,SEEK_SET); /* 跳到指定位置 */
do
{
ch=fgetc(fp); /* 读入字符 */
if(ch!=EOF) putchar(ch); /* 输出字符 */
}while(ch!='\n'&&ch!=EOF);
}
fclose(fp); /* 关闭文件 */
return 0;
}
展开全部
喊你编写一个程序,有以下要求:
1.打开一个文件,文件名是交互方式获取,意思是你得让用户输入文件名。
2.程序中应该有一个循环。
3.这个循环每次让用户输入数值(表示文件的位置),然后打印(应该是在屏幕上)出这个位置之后及其换行符('\n')之间的部分。
4.如果用户输入的是非数字字符,则循环退出。
1.打开一个文件,文件名是交互方式获取,意思是你得让用户输入文件名。
2.程序中应该有一个循环。
3.这个循环每次让用户输入数值(表示文件的位置),然后打印(应该是在屏幕上)出这个位置之后及其换行符('\n')之间的部分。
4.如果用户输入的是非数字字符,则循环退出。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编写一个程序,打开一个文本文件的名称,得到交互。成立了一个循环,要求用户输入文件的位置。然后程序应该打印出该位置的启动文件的一部分,继续下一个换行符。让非数字输入终止用户输入回路
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在线等候也没用了,去睡觉去吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询