Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualTudor Nita

Posted 20 August 2012 - 05:39 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 ambient color ? sscanf(buffer, "%c %f %f %s", &temp, &someFloat, &someOtherFloat, &aString); break; }}[/source]

#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]

#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]

PARTNERS