1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <stdio.h>
#include <stdlib.h>
#include "IONmodel.h"
#include <string.h>
IONmodel* ION_loadModel(const char* filename, char **model){
int size = 0;
FILE *file = fopen(filename, "r");
if (file == NULL)
{
printf("ERROR OPENING FILE!");
return -1; // -1 means file opening fail
}
fseek(file, 0, SEEK_END);
size = ftell(file);
printf("Size of file: %d",size);
fseek(file, 0, SEEK_SET);
char line[size];
//string array of rows and columns
char stringArray[70000][51];
int i = 0;
int text = 0;
while( fgets(line, sizeof(line), file) != NULL)
{
printf(line);
for(text = 0; text <= sizeof(line); text++){
stringArray[i][text] = line[text];
}
i++;
}
fclose(file);
//future ints to read in as the file 'seperates' into sections
int v[i][51];
int vt[i][51];
int f[i][51];
//temporary float
float temp = 0.000000;
//iterators for the 2D array to split into sections
int j =0;
int k =0;
for(j = 0; j < i; j++){
if(strncmp (stringArray[j], "v ",3) == 0){
printf("Entered v portion: ");
//want to use sizeof for proper measurement
// for(k = 0; k < 3; k++ ){
//SEGFAULT HERE
temp = atof(stringArray[0][0]);
printf(" %g", temp);
// }
}
else if(strncmp (stringArray[j], "vt ",3) == 0){
printf("Entered vt portion: ");
}
else if(strncmp (stringArray[j], "f ",2) == 0){
printf("Entered f portion: ");
}
}
//just return something for now
return size;
}
//}
int main()
{
ION_loadModel("AK74.obj", 'model');
return 0;
}
|