Message from C, C++ discussions

November 2019

— I'm interesting in 3d graphics but my current knowledge are very limited and i have merely experience with 2d. I think that really the best way is to start from game engine book.

Message permanent page


Afaik scanf returns the number of successfully parsed and assigned inputs - for example if you want to read one int you could check if scanf return something which is NOT one- then you know something went wrong


while (scanf(“%i”, &somenum) != 1)

— Something like that like?

— I guess you want to run the loop as long the input is valid :) so in this case you should do

while(scanf("%i", &somenum) == 1)

Message permanent page

— The while loop runs as long as one input value is succesfully parsed and assigned - that should be it

Message permanent page

— Thank you

— Haha ^^ your welcome

— Is it possible to use an if statement instead of a while loop?

— If scanf equals to 1 else …

— Sure for example:

if(scanf("%i", &somenum)) { 
} else {
//Dammit something went wrong
the == 1 is implicit because 0 evaluates to false and everything else to true so 1 is true

Message permanent page

— Nice