The following program shows how data is entered into a string, character by character and how data is obtained from a string character by character.
/* Program demonstrate how string are accessed
Data entered in a string character by character and displayed character by character */
This program is similar to that used for accessing integer arrays. Here ‘\0’ is automatically added to str_name after end of Block 1.
Strings have a wide use in text manipulation. Hence a number of other methods are provided for easy access of strings since we know that ‘\0’ is the terminating character of any string. We can simplify block 2.
‘C’ provides a special format specifier, “%s” for inputting a string and displaying it, with the help of which entire string can be accessed instead of going character by character. Block 1 can be change toscanf (“%s”, str_name);
Block 2 can be changed to printf (“%s”, str_name); counter ‘j’ is not required in this case.
The drawback of scanf and printf is that they can handle only one word at a time. The function gets and puts, discussed earlier can be used as an alternative, they can handle multiword strings.
C Related Interview Questions
|DBMS Interview Questions||C++ Interview Questions|
|C & Data Structures Interview Questions||Java Interview Questions|
|Go (programming language) Interview Questions||F Sharp (programming language) Interview Questions|
|C preprocessor Interview Questions||R Programming language Interview Questions|
|D Programming Language Interview Questions||Lua (programming language) Interview Questions|
|Embedded C Interview Questions|
Introduction To C-programming
Data Types And Storage Classes
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.