#include <stdio.h>
int main()
{
#define MAXREAD 1024
FILE *f;
char s[MAXREAD+1], temp_read[MAXREAD+1], temp_val[MAXREAD+1];
int c, eq_flag;
f=fopen("conf.txt","r");
if (!f) {
printf("I can't find conf.txt... ");
return 1;
} else {
while (fgets(s,MAXREAD,f)!=NULL) {
//printf("size is %d\n", sizeof(s));
if (s[0] != '#') {
c = 0;
eq_flag = 0;
while (c < sizeof(s) && s[c] != '\n' && s[0] != '\0') {
if (s[c] != '=' && eq_flag == 0) {
/**
* Till we don't hit =, we put everything
* in a temp char var.
*/
strncpy(temp_read, s, c);
printf("%s\n", temp_read);
} else {
/**
* We hit a =, go to next char and set the value
*/
eq_flag = 1;
strncpy(temp_val, s, c+1);
}
c++;
}
}
/**
* Try and display what we have.
*/
temp_read[c+1] = '\0';
temp_val[c+1] = '\0';
printf("Key: %s | Value: %s\n", temp_read, temp_val);
}
}
fclose(f);
return 0;
}