???OY 2015-10-30 14:33 采纳率: 44.4%
浏览 1674
已采纳

这个小程序while里的每一步解释?

#include
#include
#define MAX 81

int main(void)

{
char name[30],content[MAX];
int row,column;
FILE *fp;
printf("input the name of file:");
gets(name);
if( ( fp=fopen(name,"r") ) == NULL )
{
printf("Can't open %s",name);
exit(1);
}
printf("input the row and column to output:");
while ( scanf("%d%d",&row,&column) == 2 )//求每一步解释
{
row--,column--;
fseek(fp,0,SEEK_SET);
while (row--) fgets(content,MAX,fp);//简便起见,未做一些越界判断
fseek(fp,column,SEEK_CUR);
fgets(content,MAX,fp);
printf(content);
printf("input the start position to output:");
}
printf("Quit\n");

return 0;

}
编写一个程序,打开一个文本文件,文件名通过交互方式获得。建立一个循环,请求用户输入一个文件位置。然后程序打印文件中从该位置开始到下一换行符之间的部分。用户通过输入非数字字符来终止输入循环。
while循环里的都是啥意思?row,column的作用??

  • 写回答

1条回答 默认 最新

  • ysuwood 2015-10-31 00:44
    关注
        while ( scanf("%d%d",&row,&column) == 2 )//读入行、列2个值后进入循环,例如读入4 3;读入不是1个值就退出循环
        {
            row--,column--;//行列值各减1,为3 2
            fseek(fp,0,SEEK_SET);//定位文件指针到开头
            while (row--) fgets(content,MAX,fp);//读3行
            fseek(fp,column,SEEK_CUR);//定位文件指针从当前位置后移2列
            fgets(content,MAX,fp);//读入从当前位置读入1行
            printf(content);//输入读入的内容
            printf("input the start position to output:");
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据