#include<stdio.h>
#include<string.h>
/* Program to print a non repeated character in string
*
*/
int main()
{
int count[256] = {0}; /* count of the characters */
char string[20];
int i;
printf("Enter the string \n");
scanf("%s",string);
for (i = 0;i < strlen(string)-1;i++) {
count[*(string+i)]++; /* increments the count based on ASCII Range */
}
for (i = 0;i < strlen(string)-1;i++) {
if (count[*(string+i)]== 1) { /* Count with 1 is the character */
printf("count = %d,char = %c\n",count[*(string+i)],*(string+i));
break;
}
}
return 0;
}
Input -
Enter the string -
teeths
Output -
count = 1,char = h
#include<string.h>
/* Program to print a non repeated character in string
*
*/
int main()
{
int count[256] = {0}; /* count of the characters */
char string[20];
int i;
printf("Enter the string \n");
scanf("%s",string);
for (i = 0;i < strlen(string)-1;i++) {
count[*(string+i)]++; /* increments the count based on ASCII Range */
}
for (i = 0;i < strlen(string)-1;i++) {
if (count[*(string+i)]== 1) { /* Count with 1 is the character */
printf("count = %d,char = %c\n",count[*(string+i)],*(string+i));
break;
}
}
return 0;
}
Input -
Enter the string -
teeths
Output -
count = 1,char = h
Comments