STRING FUNCTION

 C supports a wide range of functions that manipulate null-terminated strings-


   1.CHECK MOBILE NUMBER IS CORRECT
                             OR NOT: 

#include<stdio.h>
#include<string.h>
int main()
{
char mn[200];
printf("Enter mobile number\n");
gets(mn);
if(strlen(mn)==10)
printf("Number is correct");
else
printf("Incorrect Number");
}

•OUTPUT 

Enter mobile number 
9678513240
Mobile number is correct.

    2.LOGIN PROGRAMME USING STRING:

#include<stdio.h>
#include<string.h>
int main()
{
char u[200]="easy@gmail.com",p[200]="ani@789";
char u1[200],p1[200];
printf("Enter username\n");
gets(u1);
printf("Enter password\n");
gets(p1);
if(strcmp(u,u1)==0&&strcmp(p,p1)==0)
printf("Login Successfully");
else
printf("Wrong username or password");
}

•Output 

Enter username 
Easy@gmail.com 
Enter password 
Sand@123
Login successfully 

   3.CHECK GIVEN STRING IS PALINDROME
                            OR NOT

#include<stdio.h>
#include<string.h>
int main()
{
char s[200],rev[200];
printf("Enter any string\n");
gets(s);
strcpy(rev,s);
strrev(rev);
if(strcmp(s,rev)==0)
printf("%s is palindrome string",s);
else
printf("%s is not palindrome string",s);
}

•Output 

Enter any string 
Madam
Madam is Palindrome string

       4 REVERSE STRING WITHOUT USING                                  FUNCTION: 

#include<stdio.h>
int main()
{
char s[200];
int length=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
length++;
printf("Reverse of %s is given below\n",s);
for(int j=length-1;j>=0;j--)
printf("%c",s[j]);
}

•Output 

Enter any string
Easy
Reverse of easy is given below
Ysae

    5.FIND LENGTH OF STRING WITHOUT                          USING FUNCTION: 

#include<stdio.h>
int main()
{
char s[200];
int count=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
count++;
}
printf("Length of string is %d",count);
}

•Output 

Enter any string
Easy 
Length of string is 4.

       6.COUNT ONLY ALPHABET IN STRING: 

#include<stdio.h>
int main()
{
char s[200];
int alpha=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
   if((s[i]>=65&&s[i]<=90)||(s[i]>=97&&s[i]<=122))
   alpha++;
}
printf("Total Alphabet=%d",alpha);
}

•Output 

Enter any string
Easy123@gmail.com
Total alphabet =12

        7.COUNT ONLY DIGITS IN STRING: 

#include<stdio.h>
int main()
{
char s[200];
int digit=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
   if(s[i]>=48&&s[i]<=57)
   digit++;
}
printf("Total Digits=%d",digit);
}

•OUTPUT 

Enter any string
Easy123@gmail.com
Total digits=3

        8.COUNT ONLY SPECIAL SYMBOL
                       IN A STRING :

#include<stdio.h>
int main()
{
char s[200];
int special=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
   if((s[i]>=65&&s[i]<=90)||(s[i]>=97&&s[i]<=122))
   {
   }
   else if(s[i]>=48&&s[i]<=57)
   {
   }
   else
   special++;
}
printf("Total Special Symbol=%d",special);
}

•Output 

Enter any string
Easy123@gmail.com
Total special symbol =2

      9.COUNT TOTAL NUMBER SPACE IN A                                   SENTENCE: 

#include<stdio.h>
int main()
{
char s[200];
int space=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
   if(s[i]==' ')
   space++;
}
printf("Total space in this sentence=%d",space);
}


•OUTPUT 

Enter any string 
Infismasher is best website to learn coding.
Total space in this sentence =6

   10.COUNT NUMBER OF VOWEL AND                         CONSONANT IN A STRING: 

#include<stdio.h>
int main()
{
char s[200];
int vowel=0,consonent=0;
printf("Enter any string\n");
gets(s);
for(int i=0;s[i]!='\0';i++)
{
   if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
   vowel++;
   else
   consonent++;
}
printf("Total Vowel=%d and Consonent=%d",vowel,consonent);
}

•OUTPUT 

Enter any string 
Infismasher 
Total vowel =3  and consonent =8

Comments

Popular posts from this blog

SWITCH PROGRAMME