Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Sunday, August 21, 2011

Check wheather the entered string is Palidrone or not.

//Program to check wheather the entered string is Palidrone or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j,k,f=1;
char c[50],a[50]={'\0'},ch;
clrscr();
printf("\nEnter the string: ");
for(i=0;i<=50;i++)
{
 ch=getchar();
 if(ch=='\n')
 {
 c[i]='\0';
 break;
 }
 else
 {
  c[i]=ch;
 }
}
printf("Entered string is:");
puts(c);
for(k=0,j=i-1;j>=0;j--,k++)
{
 a[j]=c[k];
}
printf("reversed string is:");
puts(a);

for(k=0;k<i;k++)
{
 if(c[k]!=a[k])
 {
  f=0;
  break;
 }
}
if(f==1)
printf("entered string is palidrone");
else
printf("entered string is not palidrone");
getch();
}

Program to show the concept of gets and puts function.

//Program to show the concept of gets and puts function.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int l;
clrscr();
printf("Enter the string: ");
gets(str);
l=strlen(str);
printf("The string is:");
puts(str);
printf("the length of string is %d",l);
getch();
}

Saturday, August 20, 2011

Find occurance of given character in string.

//Program to find occurance of given character in string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],c;
int o,i,l;
clrscr();
printf("program to find occurance of given character in string");
printf("\n Enter the string: ");
gets(str);
l=strlen(str);
printf("Please enter the character whose number of occurances u want to find: ");
c=getche();
o=0;
for(i=0;i<l;i++)
{
 if(str[i]==c)
 {
 o=o+1;
 }
}
printf("\n the number of occurances of given character is %d",o);
getch();
}

Friday, August 19, 2011

Program to find length of entered string.

//Program to find length of entered string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],c={0};
int l,i=-1;
clrscr();
printf("Enter the string: ");
while(1)
{
   i=i+1;
   scanf("%c",&c);
   if(c=='\n')
   {
      str[i]='\0';
      break;
   }
   str[i]=c;
}
l=strlen(str);
printf("The string is:");
puts(str);
printf("the length of string is %d",l);
getch();
}

Program to sort a entered strings using Bubble sort.

//Program to sort a entered strings using Bubble sort.
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char n[10][20],temp[20];
int i,j;
clrscr();
printf("enter the names: ");
for(i=0;i<5;i++)
scanf("%s",&n[i]);
printf("entered names are:");
for(i=0;i<5;i++)
 printf("\n %s",n[i]);
 for(i=0;i<4;i++)
  {
   for(j=0;j<4-i;j++)
    {
     if(strcmp(n[j],n[j+1])>0)
     {
      strcpy(temp,n[j]);
      strcpy(n[j],n[j+1]);
      strcpy(n[j+1],temp);
     }
    }
   }
 printf("sorted names are:");
 for(i=0;i<5;i++)
 printf(" \n%s",n[i]);
 getch();
}

Next Home
Twitter Delicious Facebook Favorites More