1.Print string with the help of pointer.
#include<stdio.h>
void Display(char *Brr)
{
while(*Brr != '\0')
{
printf("%c\n",*Brr);
Brr++;
}
}
int main()
{
char Arr[50];
printf("Enter Your Name\n");
scanf("%[^'\n']s",Arr);
Display(Arr);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
2.Write a program to find length of string.(or make own strlen function).
#include<stdio.h>
unsigned int strlenX(char *str)
{
int iCnt=0;
if(str==NULL)
{
return 0;
}
while(*str!='\0')
{
iCnt++;
str++;
}
return iCnt;
}
int main()
{
char Arr[50];
int iRet=0;
printf("Enter Your Name\n");
scanf("%[^'\n']s",Arr);
iRet=strlenX(Arr);
printf("Length of string is : %d\n",iRet);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
3.Write a program to find length of string.(or make own strlen function).If string is NULL then end program.
#include<stdio.h>
typedef unsigned int UINT;
UINT strlenX(char *str)
{
int iCnt=0;
if(str==NULL)
{
return 0;
}
while(*str!='\0')
{
iCnt++;
str++;
}
return iCnt;
}
int main()
{
char Arr[50];
UINT iRet=0;
printf("Enter Your Name\n");
scanf("%[^'\n']s",Arr);
iRet=strlenX(Arr);
printf("Length of string is : %u\n",iRet);
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
4.Write a program to Check whether character is in between a to z or not
#include<stdio.h>
#include<stdbool.h>
bool CheckSmall(char c)
{
if((c>='a') && (c<='z'))
{
return true;
}
else
{
return false;
}
}
int main()
{
char ch ='\0';
bool bRet= false;
printf("Enter Character : \n");
scanf("%c",&ch);
bRet=CheckSmall(ch);
if(bRet==true)
{
printf("It is small\n");
}else
{
printf("It is not small\n");
}
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
5.Write a program to check whether it is Digit or not
#include<stdio.h>
#include<stdbool.h>
bool CheckDigit(char c)
{
if((c>='0') && (c<='9'))
{
return true;
}
else
{
return false;
}
}
int main()
{
char ch ='\0';
bool bRet= false;
printf("Enter Character : \n");
scanf("%c",&ch);
bRet=CheckDigit(ch);
if(bRet==true)
{
printf("It is digit\n");
}else
{
printf("It is not digit\n");
}
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
6.