All pastes #15974 Raw Edit

Untitled

public c v1 · immutable
#15974 ·published 2005-06-27 13:24 UTC
rendered paste body
// _open// Oeffnen.// Erwartete Parameter://		FILE* openfile: Zeiger auf File (fopen)//		char* path: Dateipfad (String bzw. Array of character)//		float*** matrix: Zeiger auf Matrix (wo die ausgelesenen Werte gespeichert werden) (2D-Arr)int _open(FILE* openfile, char *path, float ***matrix){	openfile = fopen(path, "r");	if (openfile == NULL) return 0; // Datei existiert (hoechswahrscheinlich) nicht.	// Matrixsize checken	//// Erster Eintrag in Datei ist die Groesse der Matrix als int. (z.B. 3 --> 3x3 Matrix)	int size = 0;	fscanf(openfile, "%i\n", &size);	// Matrix memory allocation	genoutmatrix(matrix, size);	// Ugly hack incoming (pt.1)	float *mmatrix = (float*)malloc(size*size);	// Datei auslesen	int i = 0, j = 0, n = 0;	float buff;	while ( !feof(openfile) ) 	{		fscanf(openfile, "%f\n", &buff);		// Hack pt. 2		mmatrix[i++] = buff;	}    // Copy hack in 2d array (1d --> 2d transfer)	for (i = 0; i < size; ++i) {		for (j = 0; j < size; ++j) {			(*matrix)[i][j] = mmatrix[n++];		}	}	fclose(openfile);	return 1;}