NTP 文件的存储 C IP 地址

#include <stdio.h>
#include <string.h>
#define NTP_TIME "/etc/ambaipcam/IPC_Q313/config/NTPaddr.txt"

int main()
{
FILE *NTPfp ;
char szNTP[50][255],ntpjudge[100];
char addr[255],addrbuf[255];
char NTPaddress[255]; //-------------要改的NTP地址
strcpy(NTPaddress,"192.168.1.139");
int i,Lid=-1;
int judge;
memset(szNTP,0,sizeof(szNTP));
strcpy(ntpjudge,"1");

if((NTPfp=fopen(NTP_TIME,"r"))==NULL)
{
printf("can not open file!\n");
}
while(fgets(addr,256,NTPfp))
{
Lid++;
memset(addrbuf,0,sizeof(addrbuf));
if(strstr(addr,"NTP")!=NULL) //判断NTP是否打开
{
snprintf(addrbuf,sizeof(addrbuf)," NTP=%s\n",ntpjudge);
strcpy(szNTP[Lid],addrbuf);
}
else if(strstr(addr,"address")!=NULL) //判断文件中哪一行是address
{
snprintf(addrbuf,sizeof(addrbuf)," address=%s\n",NTPaddress);
strcpy(szNTP[Lid],addrbuf);
}
else
strcpy(szNTP[Lid],addr);
}
fclose(NTPfp);

if((NTPfp=fopen(NTP_TIME,"w"))==NULL) //写入NTPaddr.txt
{
printf("can not open file!\n");
return;
}
else
{
for(i=0;i<=Lid;i++)
{
fputs(szNTP[i],NTPfp);
}
fclose(NTPfp);
}
printf("ntpend=%s\n",szNTP[0]);
printf("address=%s\n",szNTP[1]);
}

转载于:https://www.cnblogs.com/qingjoin/archive/2012/03/22/2411468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值