prowessapps.in String Handling Programs

 C Program to accept a sentence using scanf function.

#include<stdio.h >
int main() {
 char str[50];
 printf("Enter a Sentence:\n");
 scanf("%[^\n]", str);
 printf("Sentence is:\n%s", str);
 return 0;
}
OUTPUT :
Enter a Sentence:
C was Developed in 1972.
Sentence is:
C was Developed in 1972.

 C Program to find the length of a string

#include<stdio.h>
int main( ) {
 char a[100];
 int i=0, length = 0;
 printf("Enter a String : ");
 gets(a);
 while(a[i] != '\0') {
  length++;
  i++;
 }
 printf("Length = %d",length);
 return 0;
}
OUTPUT :
Enter a String : C Prowess
Length = 9

 C Program to accept a paragraph(till @) using scanf function.

#include<<stdio.h>
int main() {
 char str[150];
 printf("Enter a Paragaraph to exit enter @:");
 scanf("%[^@]", str);
 printf("Paragraph is: %s",str);
 return 0;
}
OUTPUT :
Enter a Paragaraph to exit enter @: C is a general-purpose,
 procedural,
 language@
Paragraph is:
 C is a general-purpose, procedural, language

 C Program to copy one string to another string.

#include<stdio.h>
int main( ) {
 char a[100],b[100];
 int i=0;
 printf("Enter a String : ");
 gets(a);
 while(a[i] != '\0') {
  b[i] = a[i];
  i++;
 }
 b[i] = '\0';
 printf("Copied String = : ");
 i=0;
 while(b[i] != '\0') {
  printf("%c",b[i]);
  i++ ;
 }
 return 0;
} 
OUTPUT :
Enter a String : C Prowess
Copied String = : C Prowess

 C Program to Compare two String

#include<stdio.h>
int main( ) {
 char a[100],b[100];
 int i=0;
 printf("Enter 1st String : ");
 gets(a);
 printf("Enter 2nd String : ");
 gets(b);
 while(a[i] == b[i]) {
  if(a[i]=='\0' || b[i]=='\0') {
    break;
  }
  i++;
 }
 if(a[i]=='\0' && b[i]=='\0'){ 
  printf("Strings are same.\n");
 }
 else {
  printf("Strings are not same.\n");
 }
 return 0;
}
OUTPUT :
Enter 1st String : C Prowess
Enter 2nd String : C Prowess
Strings are same. 

 C Program to Concatenate two String.

#include<stdio.h>
int main( ) {
 char a[100],b[100];
 int i=0, j=0;
 printf("Enter 1st String : ");
 gets(a);
 printf("Enter 2nd String : ");
 gets(b);
 while(a[i] != '\0') {
  i++;
 }
 while(b[j] != '\0') {
  a[i]= b[j];
  i++; 
  j++;
 }
 a[i] = '\0';
 i=0;
 printf("After Concat : ");
 while(a[i] !='\0') {
 printf("%c",a[i]);
 i++;
 }
 return 0;
}
OUTPUT :
Enter 1st String : C Programming 
Enter 2nd String : Prowess
After Concat : C ProgrammingProwess


 C Program to Reverse a String.

#include<stdio.h>
int main( ) {
 char orig[100], rev[100];
 int len=0, i=0, j;
 printf("Enter a String : ");
 gets(orig);
 while(orig[i] != '\0') {
  len ++;
  i++;
 } 
 for (i=len-1, j=0; i>=0; i--, j++){
  rev[j] = orig[i];
 }
 rev[j] = '\0';
 printf("After Reverse : %s\n", rev);
 return 0;
}
OUTPUT :
Enter a String : prowess
After Reverse : sseworp

 C Program to check given string is Palindrome or not.

#include<stdio.h>
int main( ) {
 char a[100];
 int beg, mid, last, len=0;
 int flag = 1;
 printf("Enter a String : ");
 gets(a);
 while(a[len] != '\0'){
  len++;
 }
 last = len - 1;
 mid = len/2;
 for (beg=0; beg < mid; beg++){
  if (a[beg] != a[last]) {
   flag = 0;
   break;
  }
   last--;
 }
 if (flag == 1){
  printf("String is Palindrome ");
 }
 else {
  printf("String is not Palindrome");
 }
 return 0;
}
OUTPUT :
OUTPUT 1:
Enter a String : prowess
String is not Palindrome

OUTPUT 2:
Enter a String : malayalam
String is Palindrome

 C Program to convert in uppar case.

#include<stdio.h>
int main( ) {
 char a[100],i=0;
 printf("Enter a string : ");
 gets(a);
 while (a[i] != '\0') {
  if (a[i] >= 'a' && a[i] <= 'z') {
   a[i] = a[i] - 32;
   }
   i++;
 }
 printf("After Conversion: %s", a);
 return 0;
}
OUTPUT :
Enter a string to convert in upper case : prowess
After Conversion:  PROWESS

 C Program to remove all vowels from a string.

#include<stdio.h>
int check(char); 
int main( ) {
 char a[100], b[100];
 int i, j = 0;
 printf("Enter a string : ");
 gets(a);
 for(i = 0; a[i] != '\0'; i++) {
  if(check(a[i]) == 0) {       
   b[j] = a[i];
   j++;
  }
 }
 b[j] = '\0';
 printf("String after removing vowels : %s\n", b);
 return 0;
}

int check(char c) {
  switch(c) {
   case 'a':
   case 'A':
   case 'e':
   case 'E':
   case 'i':
   case 'I':
   case 'o':
   case 'O':
   case 'u':
   case 'U':
      return 1;
   default:
      return 0;
  }
}
OUTPUT :
Enter a string : prowess
String after removing vowels : prwss

 C Program to find frequency of a character in a string.

#include<stdio.h>
int main() {
 char str[40],c;
 int i,count=0;
 printf("Enter a String :");
 gets(str);
 printf("Enter a character :");
 scanf("%c",&c);
 for(i=0 ; str[i] !='\0' ;i++) {
 if(str[i]==c) {
     count++;
   }
 }
 printf("%d time(s).",count);
 return 0;
}
OUTPUT :
Enter a String : C PROWESS APP
Enter a character : P
3 time(s).


Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved