String Programs Resume
String Programs Resume
STRING PROGRAMS:
Here, you will learn how to read and compare two strings using pointers in C programming
language? In this program, we are taking two strings with maximum number of characters (100)
MAX using pointers and comparing the strings character by characters.
We have posted programs on strings in C language, now in this post we are going to discuss about array
of strings in C.
This program will read a string and print Capitalize string, Capitalize string is a string in which first
character of each word is in Uppercase (Capital) and other alphabets (characters) are in Lowercase (Small).
For example:
If input string is "hello friends how are you?" then output (in Capitalize form) will be "Hello Friends
How Are You?".
Here, we are reading a character array/string (character array is declaring with the maximum number of
character using a Macro MAXthat means maximum number of characters in a string should not more
than MAX (100), then we are reading a character to find the occurrence and counting the characters which
are equal to input character.
For example:
If input string is "Hello world!" and we want to find occurrence of 'l'in the string, output will be 'l' found
3 times in "Hello world!".
There are many string manipulation programs and string user defined functions, this is an
another program in which we will learn to count the length of each word in given string.
In this exercise (C program) we will read a string, like "Hi there how are you?" and it will print the word
length of each word like 2, 5, 3, 3, 4.
Input
Hi there how are you?Output
2, 5, 3, 3, 4
Logic to implement:
Logic to implement
1. Eliminate first character of the string (first character of first word) by shifting other character to
the left.
2. Eliminate the first character of other word (by checking whether there is an index has space and
index+1 (next to index where space found) non space and shift other characters to the left.
3. Run this process until NULL not found in the parent loop.
Given a string and we have to copy it in another string, also find and print the total number of
copied characters using C program.
Example:
Input:
String 1 (Input string): "This is a test string"
Logic:
Copy character by character from string 1 to the string 2 and use a loop counter which is initialized by 0,
after copying each character, increase the loop counter. At the end, assign NULL (‘\0’) to the target (string
2) and loop counter will be the total number of copied characters.
In the given program, we have created a user defined function to copy one string to another string and
returning the total number of copied characters.
Where,
Parameters:
o char *target - pointer to target string in which we will copy the string
o char *source - pointer to source string whose value we want to copy
return type: - int : total number of copied characters
11.
Given a string with spaces and we have to remove all spaces from it using C program.
Without using other temporary string, in this program - we are reading a string from the user and then
printing the string (by updating the same string variable) after removing all spaces from it.
Example:
Input:
String: "C is the master of all"
Output:
String: "Cisthemasterofall"
Input:
String: "I love includehelp.com"
Output;
String: "Iloveincludehelp.com"
12.
So, first of all, we have to understand - what is a sentence case? A string is in a sentence case, if first
character of each sentence is an uppercase character.
Example:
Input string: "hello how are you?"
Output:
Sentence case string is: "Hello how are you?"
13.
If string contains alphabets and numbers both (or anything with the alphabets), program to check the
alphabets, if found then program will remove them from the string.
Example:
Input:
String is: "hello123"
Output:
Final string is: "123"
Input:
String is: "Call 100"
Output:
Final string is: "100"
14.