I wouldn't use iostream. Something like this works for me. Imagine an input file like:
# a comment
a 3.5 3.5 yay_some_text
a 3.2 4.5 yay_some_more_text
[source lang="java"]FILE *pFile = fopen(filePath, "r"); // the file to loadchar buffer[512]; // character bufferchar temp;// read each line into the bufferwhile (fgets(buffer, sizeof(buffer), pFile)){ // switch based on leading type switch (buffer[0]) { case '#': // do nothing, it's a comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] break; case 'a': // set ambient color ? sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &aString); break; }}[/source]
Show differencesHistory of post edits
#2Tudor Nita
Posted 20 August 2012 - 05:38 AM
I wouldn't use iostream. Something like this works for me. Imagine an input file like:
# a comment
a 3.5 3.5 yay_some_text
a 3.2 4.5 yay_some_more_text
[source lang="java"]FILE *pFile = fopen(filePath, "r"); // the file to loadchar buffer[512]; // character bufferchar temp;// read each line into the bufferwhile (fgets(buffer, sizeof(buffer), pFile)){ // switch based on leading type switch (buffer[0]) { case '#': // do nothing, it's a comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] break; case 'a': // set scene/wide ambient color sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &yetAnotherFloat, &aString); break; }}[/source]
# a comment
a 3.5 3.5 yay_some_text
a 3.2 4.5 yay_some_more_text
[source lang="java"]FILE *pFile = fopen(filePath, "r"); // the file to loadchar buffer[512]; // character bufferchar temp;// read each line into the bufferwhile (fgets(buffer, sizeof(buffer), pFile)){ // switch based on leading type switch (buffer[0]) { case '#': // do nothing, it's a comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] break; case 'a': // set scene/wide ambient color sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &yetAnotherFloat, &aString); break; }}[/source]
#1Tudor Nita
Posted 20 August 2012 - 05:38 AM
I wouldn't use iostream. Something like this works for me. Imagine an input file like:
# a comment
a 3.5 3.5 3.5 yay_some_text
a 3.2 4.5 5.5 yay_some_more_text
[source lang="java"]FILE *pFile = fopen(filePath, "r"); // the file to loadchar buffer[512]; // character bufferchar temp;// read each line into the bufferwhile (fgets(buffer, sizeof(buffer), pFile)){ // switch based on leading type switch (buffer[0]) { case '#': // do nothing, it's a comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] break; case 'a': // set scene/wide ambient color sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &yetAnotherFloat, &aString); break; }}[/source]
# a comment
a 3.5 3.5 3.5 yay_some_text
a 3.2 4.5 5.5 yay_some_more_text
[source lang="java"]FILE *pFile = fopen(filePath, "r"); // the file to loadchar buffer[512]; // character bufferchar temp;// read each line into the bufferwhile (fgets(buffer, sizeof(buffer), pFile)){ // switch based on leading type switch (buffer[0]) { case '#': // do nothing, it's a comment [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] break; case 'a': // set scene/wide ambient color sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &yetAnotherFloat, &aString); break; }}[/source]