All pastes #265498 Raw Edit

Mine

public text v1 · immutable
·published 2006-12-03 10:11 UTC
rendered paste body
char *nameRoom(int i) {
	char *bufferA, *bufferB, character, *roomDescription[MAX_ROOMS];
	int bufferSize = DEFAULT_BUFFER_SIZE, roomNumber = 0, bufferStrlen;
	FILE *rooms;
	//rooms=fopen(ROOMS_FILE, "r");

	if ((rooms = fopen(ROOMS_FILE,"r")) == NULL) {
                  printf("Couldn't open file %s\n", ROOMS_FILE);
                  exit(1);
     } // end of if
		
	bufferA = memset(malloc(bufferSize * sizeof(char)),'\0',1);
	do {
		if (strlen(bufferA) >= (bufferSize - 1)) {
			bufferB = bufferA;
			bufferSize *= 2;
			bufferA = memset(malloc(bufferSize * sizeof(char)),'\0',1);
			strcpy(bufferA,bufferB);
			free(bufferB);
		}
		if (((character = fgetc(rooms)) != EOF) && (character != DELIMETER)) {
			bufferStrlen = strlen(bufferA);
			bufferA[bufferStrlen] = character;
			bufferA[bufferStrlen + 1] = '\0';
		} 
        else {
             roomDescription[roomNumber] = malloc(sizeof(bufferA + 1) * sizeof(char));
			 roomDescription[roomNumber] = bufferA;
			 bufferSize = DEFAULT_BUFFER_SIZE;
			 bufferA = memset(malloc(bufferSize * sizeof(char)),'\0',1);
			 roomNumber++;
			 if (roomNumber >= MAX_ROOMS)
				return roomDescription[i];
		}			
		
	} while (!ferror(rooms));
	return roomDescription[i];
}