标题:文件的访问问题
只看楼主
blue_found
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-27
 问题点数:0 回复次数:1 
文件的访问问题

#include "stdio.h"
#include "iostream"

main()
{
FILE *fp;
int i;
char ch;
char str[100];
if((fp=fopen("input.txt","w"))==NULL)
{
printf("Can not open the file.\n");
exit(0);
}

//printf("Input a string:\n");
//gets(str);
//while(str[i]!='!')
//{
// if(str[i]>='a'&&str[i]<='z')
str[i]=str[i]-32;
// fputc(str[i],fp);
// i++;
//}
//fclose(fp);
fp=fopen("input.txt","r");
fgets(str,strlen(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}

我编译这个程序后,编译的时候没有错,但是我从文件输入的数据显示出来的时候是错误的,请各位大侠帮忙看看问题出在那儿啊 。谢谢!!

搜索更多相关主题的帖子: 文件 访问 
2007-06-27 08:57
THINKERYE
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2007-6-9
得分:0 
初始化i=0即可

2007-06-27 10:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-150636-1-1.html




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

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