Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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
Cpp :: factorial MOD 998244353 
Cpp :: c++ code 2d block 
Cpp :: C++: Methods of code shortening in competitive programming 
Cpp :: changing key bindings in visual code not working 
Cpp :: random 1 diem tren man hinh bang dev c 
Cpp :: c++ calorie calculator using a for loop 
Cpp :: displaying m images one window opencv c++ 
Cpp :: temporary variable ex c++ 
Cpp :: operator using 
Cpp :: wap in c++ to understand function template 
Cpp :: how to use comparitor in priority queu in c++ 
Cpp :: object as a function argument and returning object 
Cpp :: converter python to c++ code 
Cpp :: initializer before void c++ 
Cpp :: c++ compile to msi 
Cpp :: opencv read gif c++ 
Cpp :: c++ projects 
Cpp :: converter c++ to c 
Cpp :: deletion in bst 
Cpp :: string to wstring conversion c++ 
Cpp :: can derived class access private members 
Cpp :: dream speedrun music free download mp3 
C :: run time in c 
C :: get pid c 
C :: space after format specifiers in c 
C :: tainted love 
C :: malloc int array c 
C :: fast inverse square root explained 
C :: servo motor arduino 
C :: puts without newline c 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =