"distinct char string c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "distinct char string c++" answered properly. Developers are finding an appropriate answer about distinct char string c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like distinct char string c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on distinct char string c++.
distinct char string c++
#include<stdio.h>
#include<string.h>
// 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;
}
int main() {
char str[300];
printf("Enter String: ");
gets(str);
printf("Number of Unique Characters in String: %d", count_unique_char(str));
}
Source: slaystudy.com
All those coders who are working on the C++ based application and are stuck on distinct char string c++ can get a collection of related answers to their query. Programmers need to enter their query on distinct char string c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about distinct char string c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of distinct char string c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "distinct char string c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like distinct char string c++ resolved professionally and stay updated to the latest C++ updates.