#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char **argv) //argc是参数个数 argv是参数个数的二维数组
{
int fd;
if(argc != 2){
printf("pararm error\n");
exit(-1);
}
char *readBuf = NULL;
fd = open(argv[1],O_RDWR); //可读可写的方式打开参数个数的第二个,即是要编译的目标文件
int size = lseek(fd,0,SEEK_END); //计算fd的大小
lseek(fd,0,SEEK_SET);
readBuf = (char *)malloc(size*(char)+8);
int n_read = read(fd,readBuf,size);
char *p = strstr(readBuf,"LENG="); //找到需要改的位置LENG
if(p == NULL){
printf("not found\n");
exit(-1);
}
p = p + strlen("LENG="); //指针偏移到LENG=的等号位置
*p = '5';
lseek(fd,0,SEEK_SET); //光标重新移到文件的头
int n_write = write(fd,readBuf,strlen(readBuf)); //重新写入到readBUF
return 0;
}