| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2539 人关注过本帖
标题:困惑
只看楼主 加入收藏
cccer
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2004-5-5
收藏
 问题点数:0 回复次数:2 
困惑
#include <stdio.h> main(){ FILE *input,*output; char temp[20]; char words[20]; if((output=fopen("test.txt","w"))==NULL){ printf("open file error!please check\n"); exit(0); } printf("please input words:\n"); gets(temp); if(fputs(temp,output)==EOF){ printf("write error!please check\n"); } fclose(output);

if((input=fopen("test.txt","r"))==NULL){ printf("open file error!please have a chech\n"); exit(0); } if(fgets(words,strlen(temp-1),input)==EOF){ //问题就出在这一行 printf("read error!please check\n"); } printf("%s",words); getch(); } 当用temp+1(我觉得这才对),输出的words字符串就比我输入的字符串temp少一个字符 当用temp+2,输出的words字符串就比我输入的字符串temp少2个字符 只有当用temp-1,输出的words字符串才正确 这是为什么

搜索更多相关主题的帖子: output please printf input 
2004-05-11 20:12
asdliu
Rank: 1
等 级:新手上路
帖 子:175
专家分:0
注 册:2004-4-21
收藏
得分:0 
你用strlen(temp-1)的长度就是temp的长度加1,其实你可以直接用word的长度20不就可以了吗,而不是你所想的temp+1就是temp的长度加1呀,不信你试试看

阳光版主欢迎您
2004-05-12 13:13
cyz2008poi
Rank: 1
来 自:江西南昌
等 级:新手上路
帖 子:28
专家分:5
注 册:2009-1-29
收藏
得分:0 
哇2004年的都有呀!!要是把这里面所有问的问题全部了解一遍不用自学也会了!!
2009-10-31 23:30
快速回复:困惑
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017427 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved