Search
 
SCRIPT & CODE EXAMPLE
 

C

count distinct characters in a string C

// function to return the number of unique
// characters in str[]
int count_unique_char(char* str) {

	int hash[128] = { 0 };
	int i, c = 0;

	// reading each character of str[]
	for (i = 0; i < strlen(str); ++i) {
		// set the position corresponding 
		// to the ASCII value of str[i] in hash[] to 1
		hash[str[i]] = 1;
	}

	// counting number of unique characters
	// repeated elements are only counted once
	for (i = 0; i < 128; ++i) {
		c += hash[i];
	}

	return c;

}
Comment

PREVIOUS NEXT
Code Example
C :: sleep function in c 
C :: how to open a file with open in c 
C :: how to get the ascii value of a character in c 
C :: enable disable audio listener unity 
C :: C Arithmetic Operators 
C :: remove string from string c 
C :: search in gz file 
C :: create role in psql with password 
C :: write a c program to find size of variable 
C :: Write a 64-bit program in assembly that prints Hello, world in .asm 
C :: delete string function in c 
C :: how to make a check bigger 
C :: dynamic memory allocation c 
C :: number pattern in c 
C :: Installing Tailwind 
C :: print an int c 
C :: pandoc set margins pdf 
C :: increment and decrement operator 
C :: Happy birthday in C 
C :: getline function in c 
C :: struct in struct 
C :: writing structures in c 
C :: how to take input in c 
C :: localStorage.setItem multpile arra 
C :: allocating memory for 1Mb text file in C 
C :: C Keyword typedef 
C :: can torch light bring change in chemical reaction 
C :: worst fit program in c 
C :: synopsis of fork() 
C :: brew autoremove 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =