09-05-2012, 05:15 PM
Strings in Memory
l12.ppt (Size: 191.5 KB / Downloads: 34)
Gets()
To read a string from the keyboard we must use C’s standard library functions, gets().
To use gets(), call it using the name of a character array without any index.
The gets() function reads characters until you press “Enter”
The carriage return is not stored, but is replaced by a null, which terminates the string.
The gets() function performs no bounds checking
Be sure to call it with an array large enough to hold the expected input.
Display a string, using printf().
Since the first argument to printf() is a string, you simply use str without any index as the first argument to printf(). If you wanted to output a newline, you could output str like this:
Two dimensional Arrays
A two-dimensional array is essentially an array of one-dimensional arrays and is most easily thought of in a row, column format.