All pastes #209600 Raw Edit

Stuff

public text v1 · immutable
#209600 ·published 2006-10-19 07:47 UTC
rendered paste body
/** Leser inn path, splitter på ':', og legger paths inn i et array */
void buildpath() {
	char *path = malloc(sizeof(char)*200);
	path = (char *)getenv("PATH");
	char *tmp;
	tmp = (char *)malloc(sizeof(char)*30);

	#ifdef DEBUG
		fprintf(stderr, "Path: \n%s\n\n", path);
	#endif

	/* Henter pathen og legger stiene inn i et array */
	int n = 0; char cNr = 0;
	int antStier = 0;
	for (n; n < strlen(path); n++) {
		if ((path[n] == ':') || (path[n] == '\n')) {
			tmp[cNr] = '\0';
			paths[antStier] = (char *)malloc(strlen(tmp));
			strcpy(paths[antStier], tmp);

			#ifdef DEBUG
				fprintf(stderr, "\t%s\n", paths[antStier]);
			#endif

			antStier++;
			cNr = 0;
		} else {
			tmp[cNr] = path[n];
			cNr++;
		}
	}
	#ifdef DEBUG
		fprintf(stderr, "\n");
	#endif

}