Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Learn to Code iOS Apps 2: Strings, Arrays, Objects and Classes

Part 2 of a series where you'll learn to code iOS apps using Apple's development tools. For complete beginners - no prior programming experience needed!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2689-learn-to-code-ios-apps-2-strings-arrays-objects-and-classes

Thanks for this helpful tutorial!
One question: why does the main method break out of the do-while loop after its first iteration if you remove \n from scanf("\n%c", &response);?

fpurge(stdin); //fpurge can be used which will flush out buffer and takes the input
scanf("%c", &response); //in this case no need to use \n

or

scanf("\n%c", &response);

The \n tells scanf() to read IN, and NOT save, any number of white-space, not just only ‘\n’. Reads will continue until a non-white-space is read. That non-white-space is put back into stdio for subsequent scanning.
so if you remove \n then scan is reading some unknown character(may be white space so exiting) but when \n is used the input you are giving will be in the new line in which your input will be the first character in that line.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]