बिजनेस मार्केटिंग का लो कॉस्ट फंडा , अपने मोबाइल से ऑटो sms भेजकर मार्केटिंग करे विजिट करे http://autotextsms.com/ बिजनेस मार्केटिंग का लो कॉस्ट फंडा http://autotextsms.com/

Search This Blog

Translate

c program to perform all string operation without using library function using switch case

c program to perform all string operation,c program to compare two strings,c program to concatenate two strings,c program to compare two strings using pointers,c program to compare two strings without using built in function,c program to compare two strings without using library function,c program to compare two strings without using strcmp,c program to compare two strings without using strcpy,how to declare strings in c,


c program to perform all string operation without using library function using switch case


#include
#include
int slength(char s1[10]);
void srev(char s1[10]);
void toupper(char s1[10]);
void tolower(char s1[10]);
void scpy(char s1[],char s2[]);
void ssubstr(char s1[],char s2[]);
void sconcat(char s1[],char s2[]);
void scompare(char s1[],char s2[]);
void main()
{
  int len=0,ch;
  char s1[10]="";
  char s2[10]="";
  clrscr();

  while(1)
  {
   printf("\n---------------Menu---------------------\n");
   printf("1.length\n2.Reverse\n3.copy\n4.concate\n5.compare\n");
   printf("6.substring\n7.toupper\n8.tolower\n9.exit\n");
   printf("-------------------------------------------\n");
   printf("\nEnter ur choice:");
   scanf("%d",&ch);
   switch(ch)
   {
   case 1: printf("\n Enter string:");
        fflush(stdin);
        gets(s1);
       len=slength(s1);
       printf("\n String length is:%d",len);break;
   case 2: printf("\n Enter string:");
         fflush(stdin);
        gets(s1);
       srev(s1);break;
   case 3:  printf("\n Enter string :");
          fflush(stdin);
         gets(s2);
         scpy(s1,s2);break;
   case 4:  printf("\n Enter string first:");
        fflush(stdin);
         gets(s1);
         printf("\n Enter string second:");
         gets(s2);
         sconcat(s1,s2);break;
   case 5:  printf("\n Enter string first:");
         fflush(stdin);
         gets(s1);
         printf("\n Enter string second:");
         gets(s2);
         scompare(s1,s2);break;
   case 6:  printf("\n Enter string first:");
         fflush(stdin);
         gets(s1);
         printf("\n Enter string second:");
         gets(s2);
         ssubstr(s1,s2);break;
   case 7: printf("\n Enter string:");
         fflush(stdin);
        gets(s1);
       toupper(s1);break;

   case 8: printf("\n Enter string:");
        fflush(stdin);
        gets(s1);
       tolower(s1);break;

   case 9:exit(0);

   }
    getch();
  }

}
int slength(char s1[10])
{   int i;
  for(i=0;s1[i]!='\0';i++);
  return i;
 }
 void toupper(char s1[10])
{   int i,x;
  for(i=0;i   {  x=s1[i];
      if(x >= 65 && x <= 90)
       s1[i]=s1[i];
      else
       s1[i]=x-32;

   }
    printf("%s",s1);
 }
void tolower(char s1[10])
{ int i,x;
  for(i=0;i   {  x=s1[i];
      if(x >= 97 && x <= 122)
       s1[i]=s1[i];
      else
       s1[i]=x+32;

   }
    printf("%s",s1);

 }
void ssubstr(char s1[],char s2[])
{  int i,j,flag=0;
   char ch;
    ch=s1[0];
   for(i=0;s1[i]!='\0';i++)
   {
     if(s2[0]==s1[i])//&&slength(s2)!=1||s1[slength(s1)-1]==s2[0])
      for(j=0;s2[j]!='\0';j++)
       if(s1[i]==s2[j]&& (ch==s1[i-1]||s1[slength(s1)-1]==s2[0]))
       {
    ch=s1[i];

    flag=1;


    }
       else
    flag=1;

   }
     if(flag==1)
       printf("\n String is substring:");
     else
       printf("\n String is not substring:");



}

void srev(char s1[10])
{
 int i,temp,j;
 int l=slength(s1);

 for(i=0,j=l-1;i  {
   temp=s1[i];
   s1[i]=s1[j];
   s1[j]=temp;

  }

    printf("\n %s",s1);
}
void scpy(char s1[],char s2[])
{
 int i,j;
 for(i=0,j=0;s2[j]!='\0';i++,j++)
  s1[i]=s2[j];
 s1[i]='\0';

 printf("\n New string in s1:%s",s1);
}
void sconcat(char s1[],char s2[])
{
  int i,j;
  for(i=slength(s1),j=0;s2[j]!='\0';i++,j++)
   s1[i]=s2[j];
  s1[i]='\0';
  printf("\n String after concat:%s",s1);
}

void scompare(char s1[],char s2[])
{  int i,flag=0;
  for(i=0;s1[i]!='\0'&&s2[i]!='\0';i++)
  {  if(s1[i]==s2[i])
      flag=1;
    else
     flag=0;
  }
  if(flag==1)
   printf("\n strings are  equals");
  else
   printf("\n strings are not equals");
}




c program to perform all string operation,c program to compare two strings,c program to concatenate two strings,c program to compare two strings using pointers,c program to compare two strings without using built in function,c program to compare two strings without using library function,c program to compare two strings without using strcmp,c program to compare two strings without using strcpy,how to declare strings in c,

C Program example List