Question: #include #include int countNonRepeatedCharacters ( char * compString ) { int charCount [ 2 5 6 ] = { 0 } ; / / Array

#include #include int countNonRepeatedCharacters(char *compString){ int charCount[256]={0}; // Array to store character counts int nonRepeatedCount =0; // To count non-repeated characters int length = strlen(compString); // Get the length of the string // Step 1: Count the occurrences of each character for (int i =0; i < length; i++){ charCount[(unsigned char)compString[i]]++; // Increment the count for the character }// Step 2: Count characters that are not repeated for (int i =0; i < length; i++){ if (charCount[(unsigned char)compString[i]]==1){ nonRepeatedCount++; // Increment non-repeated count if the count is 1}} return nonRepeatedCount; // Return the final count of non-repeated characters } int main(){ char compString[100]; // Buffer for the input string printf("Enter the string: "); fgets(compString, sizeof(compString), stdin); // Read the input string // Remove newline character if present size_t len = strlen(compString); if (len >0 && compString[len -1]=='
'){ compString[len -1]='\0'; }// Step 3: Get the count of non-repeated characters int result = countNonRepeatedCharacters(compString); // Step 4: Print the result printf("%d
", result); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!