variable value read from file
/etc/global
Check NIC Name@wlp8s0_eno2_eno3_eno4_bond0_bond1
VIP Address@192.168.55.56
code
char* File_Reader(char *usr_key){
char key[101], value[501];
int c3;
memset(key,'\0',sizeof(key));
memset(value,'\0',sizeof(value));
FILE *fPtr= fopen("/etc/global", "r");
while (!feof(fPtr))
{
fscanf(fPtr,"%[^@]%*[@]%[^\n]%*[\n]",key,value);
if(strcmp(key,usr_key)==0){
char *ans=NULL;
ans=(char*)malloc(sizeof(char)*strlen(value)+1);
memset(ans,'\0',strlen(value)+1);
strcpy(ans,value);
return ans;
}
}
return NULL;
}
//use
char *VipAddress=File_Reader("VIP Address");
Check NIC Name@wlp8s0_eno2_eno3_eno4_bond0_bond1
VIP Address@192.168.55.56
code
char* File_Reader(char *usr_key){
char key[101], value[501];
int c3;
memset(key,'\0',sizeof(key));
memset(value,'\0',sizeof(value));
FILE *fPtr= fopen("/etc/global", "r");
while (!feof(fPtr))
{
fscanf(fPtr,"%[^@]%*[@]%[^\n]%*[\n]",key,value);
if(strcmp(key,usr_key)==0){
char *ans=NULL;
ans=(char*)malloc(sizeof(char)*strlen(value)+1);
memset(ans,'\0',strlen(value)+1);
strcpy(ans,value);
return ans;
}
}
return NULL;
}
//use
char *VipAddress=File_Reader("VIP Address");
留言
張貼留言