Delete all occurrences of Character from the String
#include
#include
#include
void del(char str[], char
ch);
void main()
{
char
str[10];
char ch;
printf("\nEnter the string : ");
gets(str);
printf("\nEnter character which you want to delete : ");
scanf("%ch", &ch);
del(str,
ch);
getch();
}
void del(char str[],
char ch)
{
int i, j
= 0;
int size;
char ch1;
char
str1[10];
size =
strlen(str);
for (i =
0; i < size; i++)
{
if
(str[i] != ch)
{
ch1 = str[i];
str1[j] = ch1;
j++;
}
}
str1[j] =
'\0';
printf("\ncorrected string is : %s", str1);
}
Output
Enter the string :
abhiman
Enter character which
you want to delete : a
Corrected string is :
bhimn
Concat Two Strings without Using Library Function
#include
#include
void concat(char[],
char[]);
int main()
{
char
s1[50], s2[30];
printf("\nEnter String 1 :");
gets(s1);
printf("\nEnter String 2 :");
gets(s2);
concat(s1, s2);
printf("nConcated string is :%s", s1);
return
(0);
}
void concat(char s1[],
char s2[])
{
int i, j;
i =
strlen(s1);
for (j =
0; s2[j] != '\0'; i++, j++)
{
s1[i]
= s2[j];
}
s1[i] = '\0';
}
Output
Enter String 1 :
Pritesh
Enter String 2 : Taral
Concated string is :
PriteshTaral
Compare Two Strings without Using Library Function
#include
#include
int main()
{
char
str1[30], str2[30];
int i;
printf("\nEnter two strings :");
gets(str1);
gets(str2);
i = 0;
while
(str1[i] == str2[i] && str1[i] != '\0')
i++;
if
(str1[i] > str2[i])
printf("str1
> str2");
else if
(str1[i] < str2[i])
printf("str1
< str2");
else
printf("str1
= str2");
return
(0);
}
Copy One String into Other without Using Library Function
#include
#include
int main()
{
char
s1[100], s2[100];
int i;
printf("\nEnter the string :");
gets(s1);
i =
0;
while
(s1[i] != '\0')
{
s2[i]
= s1[i];
i++;
}
s2[i] =
'\0';
printf("\nCopied String is %s ", s2);
return
(0);
}
Output
Enter the string :
c4learn
Copied String is
c4learn
Program
to Convert String to Integer
#include
#include
int main()
{
int num;
char
marks[3];
printf("Please Enter Marks : ");
scanf("%s", marks);
num =
atoi(marks);
printf("\nMarks : %d", num);
return
(0);
}
Output
Please Enter Marks :
76
Marks : 76
Check Whether Entered Character is Lowercase Letter or Not
without using Library Function
#include
#include
int main()
{
char ch;
printf("\nEnter The Character : ");
scanf("%c", &ch);
if (ch
>= 'A' && ch <= 'Z')
{
printf("Character
is uppercase Letters");
}
else if (ch >= 'a' && ch <=
'z')
{
printf("Character
is Not Lowercase Letters");
}
else
{
printf("Non
alphabet character");
}
return(0);
}
Output
Enter The Character : a
Character is Lowercase Letters
No comments:
Post a Comment