#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#define BUFFSIZE 100
char sv[5]="5805";
//./tdv1.5803 -d 1 -p tdPhy_1_3_2.pa -f $tar_freq -s $tar_paraid
int update_set_freq(FILE *in)
{
char buff[100] = {0};
char *c = NULL;
char tmp[100] = {0};
do
{
c = fgets(buff,BUFFSIZE,in);
if(NULL != c){
if(0 == strncmp(c,"#update_sv by hj don't delete",10)){
sprintf(tmp,"./tdv1.%s -d 1 -p tdPhy_1_3_2.pa -f $tar_freq -s $tar_paraid",sv);
printf("******%s",c);
fputs(tmp,in);
return 0;
}
}
}
while(NULL != c);
printf( "*********fail to update set_freq*********");
return -1;
}
int main(void)
{
FILE * fp;
//while(1)
{
//sleep(3);
fp = fopen("/home/hj/workspace/test/test9/set_freq.sh","r+");
//fp = fopen("hh","r+");
update_set_freq(fp);
fclose(fp);
}
return 0;
}
1,in指针在fputs后会跳到回车后的一行
2,使用#update_sv by hj don't delete标注文件的位置
3,fputs(tmp,in),写入文件指定的位置