0% found this document useful (0 votes)
2 views5 pages

String Practice Sheet

The document is a comprehensive practice sheet for C programming focused on string manipulation. It includes a variety of exercises such as finding string length, copying, concatenating, comparing, and modifying strings, as well as tasks related to character and word counting, and string formatting. Additionally, it covers concepts like palindromes, pangrams, anagrams, and provides examples of string initialization and function usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

String Practice Sheet

The document is a comprehensive practice sheet for C programming focused on string manipulation. It includes a variety of exercises such as finding string length, copying, concatenating, comparing, and modifying strings, as well as tasks related to character and word counting, and string formatting. Additionally, it covers concepts like palindromes, pangrams, anagrams, and provides examples of string initialization and function usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

String Practice Sheet

1. Write a C program to find length of a string with and without function.


2. Write a C program to copy one string to another string with and without function.
3. Write a C program to concatenate two strings with and without function.
4. Write a C program to compare two strings with and without function.
5. Write a C program to convert lowercase string to uppercase.
6. Write a C program to convert uppercase string to lowercase.
7. Write a C program to toggle case of each character of a string.
8. Write a C program to find total number of alphabets, digits or special character in a string.
9. WAP to input a string and copy all the vowels , consonants , digits and special characters in 4 different strings then
display those 4 strings.
10. Write a C program to count total number of vowels and consonants in a string.
11. Write a C program to count total number of words in a string.
12. Write a C program to find reverse of a string with and without function.
13. Write a C program to check whether a string is palindrome or not.
14. Write a C program to reverse order of words in a given string.
15. Write a C program to find first occurrence of a character in a given string.
16. Write a C program to find last occurrence of a character in a given string.
17. Write a C program to search all occurrences of a character in given string.
18. Write a C program to count occurrences of a character in given string.
19. Write a C program to find highest frequency character in a string.
20. Write a C program to find lowest frequency character in a string.
21. Write a C program to count frequency of each character in a string.
22. Write a C program to remove first occurrence of a character from string.
23. Write a C program to remove last occurrence of a character from string.
24. Write a C program to remove all occurrences of a character from string.
25. Write a C program to remove all repeated characters from a given string.
26. Write a C program to replace first occurrence of a character with another in a string.
27. Write a C program to replace last occurrence of a character with another in a string.
28. Write a C program to replace all occurrences of a character with another in a string.
29. Write a C program to find first occurrence of a word in a given string.
30. Write a C program to find last occurrence of a word in a given string.
31. Write a C program to search all occurrences of a word in given string.
32. Write a C program to count occurrences of a word in a given string.
33. Write a C program to remove first occurrence of a word from string.
34. Write a C program to remove last occurrence of a word in given string.
35. Write a C program to remove all occurrence of a word in given string.
36. Write a C program to trim leading white space characters from given string.
37. Write a C program to trim trailing white space characters from given string.
38. Write a C program to trim both leading and trailing white space characters from given string.
39. Write a C program to remove all extra blank spaces from given string.
40. Write a C Program to input a string and check whether the string is pangram or not. A string is said to be pangram if it
contains all the alphabets of English ( Could be upper or lower )
Ex: The quick brown fox jumps over the lazy dog
41. Write a C Program to input 2 strings and check whether the strings are anagram or not. 2 strings are said to be
anagram if they contains same set of letters and length.
42. Write a program to input a word from the user and print it in the following way. For example, if the word is
PROGRAM, the program will print it as-
P
P R
P R O
P R O G
P R O G R
P R O G R A
P R O G R A M4
43. Write a program to search a middle name in the name consisting of first name, middle name and last name.
44. Write a menu driven program to perform the following task-
o Find length of a string
o Copy of one string into another
o Capitalize all letters of a string
o Reverse of string
o Comparison of two strings
45. Define string. Differentiate between ‘a’ and “a”.
46. Differentiate between character array and string. Give one example of each.
47. What are the functions used for reading a string? If you want to read your full name, which function
you will prefer ? Why?
48. What are the ways to initialize 1D and 2D string?
49. What will be the output of following program?

void main()

char str1[] = "abcd";

char str2[] = "abcd";

if(str1==str2)

printf("Equal");

else

printf("Unequal");

50. What will be the output of the following program?

void main()

{ char s[]= “Hello, World”;

printf(“>>%s<<\n”,s);

printf(“>>%20s<<\n”,s);

printf(“>>%-20s<<\n”,s);
printf(“>>%.4s<<\n”,s);

printf(“>>%-20.4s<<\n”,s);

printf(“>>%20.4s<<\n”,s);

51. What are wrong initializations of the following string arrays?

(i) char str[]={‘h’, ‘e’, ‘l’, ‘l’, ‘o’}; (ii) char str[5]={‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’};

(iii) char str[]={‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’}; (iv) char str[6]={‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’};

(v) char str[]= “hello”;

(vi) char str[][]={“hi”, “hello”, “good”, “bad”, “better”};

(vii) char str[5][]= {“hi”, “hello”, “good”, “bad”, “better”};

(viii) char str[5][10]= {“hi”, “hello”, “good”, “bad”, “better”};

52. Write a C program that reads the name of a person as input and print the name in an abbreviated
fashion, e.g., Dennis Ritchie as D.R.

53. Write a program to store name of ten cities and rewrite it in alphabetical order.

54. Write a C program to remove the white spaces from a string

55. What will be the output of following programs?


a. #include<stdio.h>

#include<string.h>

int main()

char str1[20] = "Hello", str2[20] = " World";

printf("%s\n", strcpy(str2, strcat(str1, str2)));

return 0;

b. #include<stdio.h>

int main()

char p[] = "%d\n";

p[1] = 'c';

printf(p, 65);

return 0;

c. #include<stdio.h>

#include<string.h>

int main()

printf("%d\n", strlen("123456"));

return 0;

}
d. #include<stdio.h>

int main()

char s[25] = "The cocaine man";

int i=0;

char ch;

ch = s[++i];

printf("%c", ch);

ch = s[i++];

printf("%c", ch);

ch = i++[s];

printf("%c", ch);

ch = ++i[s];

printf("%c", ch);

return 0;

You might also like