All pastes #93618 Raw Edit

Anonymous

public c v1 · immutable
#93618 ·published 2006-07-20 16:45 UTC
rendered paste body
// getconfig function by harleyg// Usage: getconfig("file", "string");//// Inside the config file should be foo = true etc.// It will search for the string and if it is set to true, return 0// else it will return 1.// Includes#include <stdio.h>#include <string.h>#include <stdlib.h>// Start getconfig functionint getconfig(char *location, char searchstr[]) {	// Variables	FILE *file;	char *w[100], string[100], line[100],	     c;	int z[100], x[100],	    i=0, v;	// Open file	file = fopen (location, "r");	// Check to see if the file was opened successfully	if (file == NULL) perror("Cannot open file");	else {		// Read each line in a loop		while(fgets(string , 100 , file) != NULL) {			x[i] = strlen(string)-1; // Put each line into an array			if(string[0] == '#') continue; // Ignor lines with #			w[i] = strchr(string,'=')-1; // Find '='			*w[i] = 0; // Set = location as 0			if(!strcmp(searchstr, string)) // Compair string				if(!strcmp("true\n", w[i]+3)) // Find 'true'					return 0; // return 0				else					return 1; // return 1			i++;		}		fclose(file); // Close file	}}