C String Manipulation programs without using Library Functions
C string manipulation programs without using Library Functions
The string is the character list, and typically we operate with library functions to read and print the entire string, but here you can find a compilation of solved c example based on string manipulation. We can perform with strings and render most programs without using string.h in the header file.
We are going to get and manipulate will character from the character list, and use our specific technic to display the string.
List of solved string manipulation programs
C program to individually print all of the VOWEL and CONSONANT characters.
During this program, we will individually print all VOWEL and CONSONANT characters from an obtained string, the logic behind whilst implementing the entire program too effectively, you just have to check if those characters are vowels to print them out like vowels and not to print them as consonants.
#include<stdio.h> int main() { character text[100]; int j; printf("Please enter any string character: "); gets(text); printf("Your String character is: "); for(j=0;text[j]!='\0';j++) { printf("%c",text[j]); } printf("\n"); printf("VOWEL Characters is: "); for(j=0;text[j]!='\0';j++) { if(text[j]=='A' || text[j]=='a' || text[j]=='E' || text[j]=='e' || text[j]=='I' || text[j]=='j' || text[j]=='O' || text[j]=='o' || text[j]=='U' || text[j]=='u') printf("%c",text[j]); } printf("\n"); printf("CONSONANT Characters is: "); for(j=0;text[j]!='\0';j++) { if(!(text[j]=='A' || text[j]=='a' || text[j]=='E' || text[j]=='e' || text[j]=='I' || text[j]=='j' || text[j]=='O' || text[j]=='o' || text[j]=='U' || text[j]=='u')) printf("%c",text[j]); } printf("\n"); return 0; }
Output:
C program to use a loop to print string one by one character.
As we notice, a string may be displayed through printf("percent s, "string variable), but in this approach, we will print string one by one character using a loop. Here the loop runs from 0 to Null.
#include<stdio.h> int main() { character text[100]; int j; printf("Please enter any string character: "); gets(text); printf("Your String character is: "); for(j=0;text[j]!='\0';j++) { printf("%c",text[j]); } printf("\n"); return 0; }
Output:
C program to count a string of upper case, lower case, and special characters.
We'll be counting upper case, lower case, and special characters in this program. The logic behind implementing this system is too simple, if it is alphabet search for lower and upper case characters, if characters are not alphabets count them as special characters, just test characters is alphabet or no.
/*C program to count upper case, lower case and special characters in a string.*/ #include<stdio.h> int main() { char text[100]; int j; int countLow,countUpp,countSpe; printf("Enter any string: "); gets(text); //here, we are printing string using printf //without using loop printf("Entered string is: %s\n",text); //count lower case, upper case and special characters //assign 0 to counter variables countLow=countUpp=countSpe=0; for(j=0;text[j]!='\0';j++) { //check for alphabet if((text[j]>='A' && text[j]<='Z') || (text[j]>='a' && text[j]<='z')) { if((text[j]>='A' && text[j]<='Z')) { //it is upper case alphabet countUpp++; } else { //it is lower case character countLow++; } } else { //character is not an alphabet countSpe++; //it is special character } } //print values printf("Upper case characters: %d\n",countUpp); printf("Lower case characters: %d\n",countLow); printf("Special characters: %d\n",countSpe); return 0; }
Output:
C program to toggle the case of all string characters.
Therefore in the program, we will toggle the case of string for all characters. The logic behind such a program is to convert the character of the lowercase letter in the uppercase letters and the upper case character in the lowercase letters, but the first test whether the letter is an alphabet or not, if this is alphabet then just do it.
#include<stdio.h> int main() { character text[100]; int k; printf("Please enter any string character: "); gets(text); printf("Your String character is: %s\n",text); for(k=0;text[k]!='\0';k++) { //check character is alphabet or not if((text[k]>='A' && text[k]<='Z')||(text[k]>='a' && text[k]<='z')) { //check for upper case character if(text[k]>='A' && text[k]<='Z') text[k]=text[k]+0x20; else text[k]=text[k]-0x20; } } printf("String after toggle case: %s\n",text); return 0; }
Output: