C Strings

Reading Strings from the terminal

The function scanf with %s format specification is needed to read the character string from the terminal.
            char address[15] ; 

Scanf statement has a draw back it just terminates the statement as soon as it finds a blank space, suppose if we type the string new york then only the string new will be read and since there is a blank space after word “new” it will terminate the string.

Reading strings

Note that we can use the scanf without the ampersand symbol before the variable name.
In many applications it is required to process text by reading an entire line of text from the terminal. The function getchar can be used repeatedly to read a sequence of successive single characters and store it in the array.
We cannot manipulate strings since C does not provide any operators for string. For instance we cannot assign one string to another directly.

Writing strings to screen

The printf statement along with format specifier %s to print strings on to the screen. The format %s can be used to display an array of characters that is terminated by the null character
For example:
can be used to display the entire contents of the array name.


Make Comments..!!

Oops!! No posts from user.

Download Android App