Working with Strings & Standard Functions 281
EXERC ISES
A] A nsw er the following questions.
1) What are strings? How are they declared?
2) What is the NULL character? Why is it important?
3) Is it possible to initialize NULL character in the string?
4) Why is it necessary to count NULL character while declaring string?
5) What is the difference between the functions strcmp () and stricmp () ?
6) What is the use of strrev () and strlen () functions?
7) What is the use of strcpy () and strdup () functions?
8) What is the difference between strcpy () and stmcpy () functions?
9) What is the difference between NU L L,1 0' and 0?
B) A nsw er the following b y selecting the appropriate option
1) The string always ends with
a) '0' character b) 'V character
c) '0 V character d) none of the above
2) What w ill be the output of the program
void main ()
{
char nm[] = {'A ' j'N 'j'S'/'I'/Oj'C' ,'0'}f
int x=0;
clrscr () ;
while (n m [x ]!= ' 0 ')
printf ("% c",n m [x + + ]);
}
a) ANSI
c) ANSIC
3) What will be the size of character array
void main ()
{
char x[]={'s','a',NULL};
p rin tf ("n %d", sizeof (x));
}
a) 3
c) 0
4) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main ()
{
char x [] ="aUb2c3d4e5f6g7h8i9j0";
int t=0;
clrscr ();
b) ANSIOC
d) none of the above
b) 2
d) none of the above
282 Programming and Data Structures
fo r (t=l;x[t]!=0& & t<=strlen(x);t+=2)
printf ("% c",x [t]);
}
a) 1234567890
c) alb2c3d4e5f6g7h8i9j0
b) abcdefghij
d) none of the above
5) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void main ()
{
char txt [] ="123450abcdef";
clrscr ();
printf ("% s ”,txt);
}
a) 12345
c) 123450abcdef
b) abcdef
d) none of the above
6) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void main ()
{
char txt [] ="ABCDEFOGHIJKL" ;
clrscr ();
printf ("% s % d ”,txt,sizeof(txt));
}
a) ABCDEF 14 b) ABCDEF0GHIJKL 14
c) ABCDEF 7 d) none of the above
C] Attem pt the following program s.
1) Write a program to arrange a set of fruit names given below in descending order (reverse
alphabetic). (Mango, Banana, Apple, Orange, Graphs, Coconut, Water melon and Papaya).
2) Write a program to arrange the following names in alphabetic order. The sorting is to be done on
the first three characters of the first name.
( Ashok, Alok, Akash, Am it, Am ol, An il, Ashish & Anand)
3) Write a program to enter some text and display the text in reverse order. (Example: "I am happy"
will be displayed as "happy am I."
4) Write a program to enter five full names of persons. Display their names, initials, and last
names.
5) Write a program to enter text through keyboard. Convert first character of each word in capital
and display the text.
6) Write a program to enter some text through the keyboard. Insert dot ( .) after every three words
in the text. The first character after every dot should be converted to capital.
7) Write a program to enter some text through the keyboard. Count the number of words that starts
from 'w'. Display such words and count them.
8) Write a program to print the entered word with all possible combinations.
9) Write a program to encrypt the text "INDIA." The output should be "KPFKC". ( ' A' is to be
replaced with 'C ', %B' with %D' and 'C ' with 'E ' and so on.)
10) Write a program to dycrypt the text "KPFKC" to get original string "INDIA".
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21