String Programs

Program to replace each string of one or more blanks by a single blank

Program to replace each string of one or more blanks by a single blank

Here is the program to replace each string of one or more blanks by a single blank. #include “stdio.h” #include “conio.h” #include “string.h” void main() { char input[100],output[100],c; int i=0,j=0; clrscr(); printf(“Enter the string\n”); gets(input); for(i=0;i<strlen(input);i++) { if(input[i]==' '&&input[i+1]!=' ') output[j++]=input[i]; else if(input[i]!=' ') output[j++]=input[i]; } output[j]=''; printf("\noutput string is\n"); puts(output); getch(); } Output: Enter […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Program to match two given strings using function

Program to match two given strings using function

This is the program which makes use of function matchany(s1,s2) which returns the first location in the string s1 where any character from the string s2 occurs, or -1 if s1 contains no character from s2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Program to arrange the string in alphabetical order

Program to arrange the string in alphabetical order

Here is the program to arrange the string in alphabetical order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include "stdio.h" #include "conio.h" #include "string.h" void main() { char str[10],temp; int i,j; clrscr(); printf("\nEnter the string : "); scanf("%s",str); for(i=0;i<strlen(str);i++) for(j=0;j<strlen(str);j++) if(str[i]<str[j]) […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

To reverse the given string using pointer

To reverse the given string using pointer

This is the program to reverse the given string and display. The program internally uses the logic of reversing the word. Logic: The approach here is to reverse the string using the pointers. Reversing the string includes the reversing the each and every words in it. After accepting a string from user, it calls a […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

To reverse the given string

To reverse the given string

Here is the program to reverse the given string and display. The program internally uses the logic of reversing the word. Logic: Reversing the string includes the reversing the each and every words in it. After accepting a string from user, it calls a function “strev” with two string arguments, the source and destination. It […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

To copy the contents of one string to another string using pointer

To copy the contents of one string to another string using pointer

This is the simple implementation of the “Copy” function using the pointers. This program copies the content of one string to another. Logic : The program asks the user to input the string to copy and stores using the pointer str1. The inner function “stcpy” takes 2 string pointers as arguments. By keeping the length […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

To copy the contents of one string to another string

To copy the contents of one string to another string

This is the simple implementation of the “Copy” function of the computer world. This program copies the content of one string to another. Logic : The program asks the user to input the string to copy and stores this as str1. The inner function “stcpy” takes 2 strings as arguments. By keeping the length as […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

To check whether the given string is palindrome-method 2

To check whether the given string is palindrome-method 2

Here is  another program, advanced version of the previous program, to check if the entered string is a palindrome. Palindrome is a string segment, which reads same from both the directions. The same method is implemented here in the program also. Logic :  The given string is referred by two names, where one is traced […]

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone