0% found this document useful (0 votes)
5 views2 pages

Character Occurrence and Duplication Removal

The document contains C programs that perform various string operations. The first program searches for the occurrence of a specified character in a string and reports its index. The second program counts how many times a character appears, while the third program removes duplicate characters from a string.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Character Occurrence and Duplication Removal

The document contains C programs that perform various string operations. The first program searches for the occurrence of a specified character in a string and reports its index. The second program counts how many times a character appears, while the third program removes duplicate characters from a string.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/******************************************************************************

occurance of each character in a sring

*******************************************************************************/
#include <stdio.h>
#include <string.h>

int main()
{
char str[] = "muralikrishna";
int n = strlen(str);
char a;
int status=0;
printf("enter search value");
scanf(" %c",&a);
for(int i=0;i<n;i++)
{
if (a==str[i])
{

printf("'%c' value found at %d\n",a,i);

status =1;
}

}
if (!status)
printf("not nound");
}

2) number of times occurances


#include <stdio.h>
#include <string.h>

int main()
{
char str[] = "muralikrishna";
int n = strlen(str);
char a;
int status=0;
int count =0;
printf("enter search value");
scanf(" %c",&a);
for(int i=0;i<n;i++)
{
if (a==str[i])
{

count ++;

status =1;
}

printf("'%c' is found %d times",a,count);


if (!status)
printf("not nound");
}

remove duplicates

#include <stdio.h>
#include <string.h>

int main()
{
char str[] = "venkatesh";
int n = strlen(str);
int count =0;
int j;

for(int i=0;i<n;i++)
{
int isduplicate =0;
for(int j=0;j<count;j++)
{
if (str[i]==str[j])
{
isduplicate =1;
break;

}
}
if (!isduplicate)
{
str[count++] = str[i];
}

}
str[count] = '\0';

printf("%s",str);
return 0;
}

You might also like