| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:求教!为什么没有输出????
只看楼主 加入收藏
Benthy2
Rank: 1
等 级:新手上路
帖 子:25
专家分:7
注 册:2011-12-16
结帖率:66.67%
收藏
已结贴  问题点数:4 回复次数:3 
求教!为什么没有输出????
下面的程序很简单,但为什么就是没有输入tomoeeow,我纳闷!请有经验人士指教!

#include<stdio.h>
main()
{
   char a[80]="tomoeeow",b[80]="",c[80]="";
   FILE *fp=NULL,*fq=NULL;

   fp=fopen("a.txt","r+");
   if(fp==NULL)  { printf("can't open this file\n ");  exit(0); }
   fprintf(fp,"%s",a);
   fgets(fp,"%s",b);
   fq=fopen("c.txt","r+");
   if(fq==NULL) {  printf("can't open this file\n ");  exit(0); }
   fprintf(fq,"%s",b);
   fgets(fq,"%s",c);
   puts(c);
   fclose(fp);
   fclose(fq);
}
搜索更多相关主题的帖子: file 
2011-12-19 08:51
少凡
Rank: 2
等 级:论坛游民
帖 子:14
专家分:31
注 册:2010-10-10
收藏
得分:0 


#include <unistd.h>
#include<stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[])
{
   char a[80]="tomoeeow",b[80],c[80];
   FILE *fp=NULL,*fq=NULL;
 
   memset(b, '\0', 80);
   memset(c, '\0', 80);   

   fp=fopen("a.txt","r+");
   if(fp==NULL)  {
      
       printf("can't open this file\n ");  
       exit(0);
   }
   
   fprintf(fp,"%s",a);
   rewind(fp);
   fread(b, 20, 1, fp);
   fclose(fp);
   printf("1=====%s\n", b);  
   
   fq=fopen("c.txt","r+");
   if(fq==NULL) {  
      
       printf("can't open this file\n ");  
       exit(0);
   }
   fprintf(fq,"%s",b);
   fread(c, 20, 1, fq);
      
   //puts(c);  //你对puts用法有点误解吧!用法如下:puts() writes the string s and a trailing newline to stdout.

   fclose(fq);
   printf("2=====%s\n", b);  
      
   return 0;
   
}


2011-12-19 10:14
linxiaomu
Rank: 1
等 级:新手上路
帖 子:14
专家分:6
注 册:2011-7-26
收藏
得分:4 
回复 楼主 Benthy2
fgets(str, n, fp)这是书上的,你的fgets(fp, %s, b);这样用是不是错了?
2011-12-19 11:21
linxiaomu
Rank: 1
等 级:新手上路
帖 子:14
专家分:6
注 册:2011-7-26
收藏
得分:0 
回复 3楼 linxiaomu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
   char a[80]="tomoeeow",b[80],c[80];
   FILE *fp=NULL,*fq=NULL;

   fp=fopen("a.txt","w");
   if(fp==NULL)  { printf("can't open this file\n ");  exit(0); }
   fprintf(fp,"%s",a);
   fclose(fp);
   fp=fopen("a.txt","r");
   fgets(b, 20, fp);
   fclose(fp);
   fq=fopen("c.txt","w");
   if(fq==NULL) {  printf("can't open this file\n ");  exit(0); }
   fprintf(fq,"%s",b);
   fclose(fp);
   fq=fopen("c.txt","r");
   fgets(c, 20, fq);
   puts(c);
   fclose(fp);

  system("PAUSE");   
  return 0;
}
我按你的方式改了一下可以运行了。不知道是不是你要的结果  我也是新手 一起学习哦
2011-12-19 11:28
快速回复:求教!为什么没有输出????
数据加载中...
 
   



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

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