All pastes #368875 Raw Edit

Anonymous

public c v1 · immutable
#368875 ·published 2007-02-23 12:13 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){	#define MAXREAD 1024    FILE *f;    char s[MAXREAD+1], temp_read[MAXREAD+1], temp_val[MAXREAD+1];    char *x;    f = fopen("conf.txt", "r");    if (!f) {        printf("I can't find conf.txt...\n");        return 1;    }     while (fgets(s, MAXREAD, f) != NULL) {        /* skip comments */        if (s[0] == '#')            continue;        x = strchr(s, '=');        if (x == NULL || x == s)            /* no '=' or if '=' is first character -> skip line */            continue;        strncpy(temp_read, s, x - s);        temp_read[x - s] = '\0';        x++;        strncpy(temp_val, x, MAXREAD);		char *z = strchr(temp_val, '\n');		if (z != NULL)			*z = '\0';		else			temp_val[strlen(x)] = '\0';		        printf("Key: %s | Value: %s\n", temp_read, temp_val);    }    fclose(f);    return 0;}