文件读写问题 [英] File read write problem

查看:120
本文介绍了文件读写问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面code.I应该改变标签和票据,但我的code不nothing.What可能是我的问题,code是这样的:

 的#include<&stdio.h中GT;
#包括LT&;&string.h中GT;
诠释的main()
{
  FILE * PFILE;  字符标记[6];
  字符code [20] =埋单;
  PFILE = FOPEN(example.asm,R +);
  如果(PFILE == NULL)
  {
    PERROR(错误);
  }
  其他
  {  而(!的feof(PFILE))
  {
    与fgets(标签,5,PFILE);    如果((标签==< BP>中)及和放大器;!(的feof(PFILE)))
    {        的fputs(code,PFILE);    }  }  }
FCLOSE(PFILE);
 返回0;
}


解决方案

您无法使用比较字符串== 运营商,因为它将两个指针之间的比较,而不是它们指向字符串,您应该使用 STRCMP(标签,< BP>中)。

I wrote the following code.I should change tags with bill but my code does nothing.What can be the problem?My code is this:

#include <stdio.h>
#include <string.h>
int main ()
{
  FILE * pFile;

  char tag [6];
  char code[20]="bill";
  pFile = fopen ("example.asm","r+");
  if (pFile==NULL)
  {
    perror("Error");  
  }
  else
  {

  while(!feof(pFile))
  {
    fgets(tag,5,pFile);

    if((tag=="<bp>") && (!feof(pFile)))
    {

        fputs(code,pFile);  

    }

  }

  }
fclose(pFile);
 return 0;
}

解决方案

You can't compare strings using the == operator since it will compare between two pointers, not the strings they point to, you should use strcmp(tag,"<bp>").

这篇关于文件读写问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆