using fscanf function
Is there a method of using fscanf to where it will read in a value
after an equal sign ? For example in the file network-config
below when using the code
fscanf (file_pointer, "%s", &var1);
the var1 variable will contain 10.4.0.1 and not
ETH1=10.4.0.1.
I could of course, read a file character by character, but I thought
fscanf would be quicker in this case.
==============================
root:~# ./test_putenv2
var1 = ETH1=10.4.0.1
==============================
root:~# cat /etc/yellowbox/network-config
ETH1=10.4.0.1
ETH0=216.143.22.145
NETMASK=255.255.255.0
GATEWAY=216.143.22.1
FIREWALLGROUP=0
HOSTNAME=printer
==============================
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *f, *file_pointer, *fopen();
char var1[21];
file_pointer = fopen ("/etc/yellowbox/network-config", "r");
fscanf(file_pointer, "%s", &var1);
printf("var1 = %s\n", var1);
fclose(file_pointer);
}
|