读一个文件里的某个值,然后写到另外一个文件内。
来源:互联网 发布:seo主管招聘 编辑:程序博客网 时间:2024/05/21 14:40
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
FILE *fp;
FILE *fpconf;
FILE *fpw;
int filenum;
int rc;
int size = 0;
char buff[8192];
char *aimbuf;
char *bimbuf;
char aimbuff[200];
char *infpname;
char *outfpname;
printf("the argc is %d/n", argc);
infpname = argv[1]; //input file
printf("infpname is %s/n", infpname);
outfpname = argv[2]; //output file
printf("outfpname is %s/n", outfpname);
fpconf = fopen(outfpname, "rb");
if (fpconf == NULL)
printf("open write file error/n");
while (fgets(buff, 8192, fpconf) != NULL) {
bimbuf = strstr(buff, "ro.product.model"); // to find whether the "ro.product.mode" is exist in the file.
if (bimbuf == NULL) {
fclose(fpconf);
fp = fopen(infpname, "rb");
fpw = fopen(outfpname, "a");
if (fp == NULL)
printf("open readfile error/n");
if (fpw == NULL)
printf("open write file error/n");
while (fgets(buff, 1024, fp) != NULL) {// to read the string which after the string <VALUE>
aimbuf = strstr(buff, "<VALUE>");
if (aimbuf) {
rc = 0;
while (*aimbuf != '>')
aimbuf++;
aimbuf++;
printf("%s/n", aimbuf);
while (*aimbuf != '<') {// return the value until "<" is found.
aimbuff[rc++] = *aimbuf;
aimbuf++;
}
printf("aimbuff is %s/n", aimbuff);
fprintf(fpw, "echo /"ro.product.model= %s/"/n", aimbuff);
break;
}
memset(aimbuff, 0, 100);
}
// free(buff);
fclose(fp);
fclose(fpw);
}
}
return 0;
}
本程序实现了,从一个input file中读出<VALUE>XXX</VALUE>的内容。写如output file 中。
在写之前,先读output file,看这个值是否存在。
- 读一个文件里的某个值,然后写到另外一个文件内。
- 通过echo将字符串、某个文件文档 加到另外一个文件的末端
- 读取一个文件然后将文件中的数据排序然后输出到另外一个文件中(冒泡排序)
- linux - shell 将7天内更新的文件复制到另外一个文件夹
- 一个xml导入到另外一个xml文件的方法
- 如何将一个文件里不包含某个字符的行输出到另一个文件?
- c++工程里一个文件怎么调用另外一个文件里的函数
- QT读取xml文件,然后写入另外一个新的xml文件
- 创建一个写入流写入一个文件到程序的临时目录里
- ios ijkplayer 直接设断点ffmpeg某个文件内函数,然后执行到断点的办法。
- 把一个文件到追加另外一个文件上
- 把一个文件到追加另外一个文件上 .
- linux复制一个文件到另外一个文件中
- 如何将一个Java对象写到文件里
- 现在我要写一个定时程序定时读取该目录下的所有txt文件到数据库,并把这些txt文件转移到另外一个目录
- 把一个机器上1天内新增的文件用rsync传送到另外一台机器
- linux下移动文件夹内所有文件到另外一个文件夹下
- 从控制台输入,然后写到文件里。
- Tomcat 6.0 安装版内存调整
- 对于访问IIS元数据库失败的解决
- 2010年6月PHP面试题
- Javascript库
- 效果非常好的PHP技巧转帖
- 读一个文件里的某个值,然后写到另外一个文件内。
- BIG-ENDIAN 和 LITTLE-ENDIAN
- 多米诺瓷砖
- 最新的php_SQL注入专题
- 遭遇变态领导
- CSS文档流与块级元素和内联元素
- asp.net母板页引用文件的路径问题
- AJAX
- AJAX