Skip to main content
added 6 characters in body
Source Link
gulpr
  • 4.6k
  • 4
  • 19

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

If o in follow is considered as "repeat" character.

void char_counter(const char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

If o in follow is considered as "repeat" character.

void char_counter(char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

If o in follow is considered as "repeat" character.

void char_counter(const char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

added 59 characters in body
Source Link
gulpr
  • 4.6k
  • 4
  • 19

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

If o in follow is considered as "repeat" character.

void char_counter(char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

void char_counter(char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

If o in follow is considered as "repeat" character.

void char_counter(char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb

Post Undeleted by gulpr
Post Deleted by gulpr
Source Link
gulpr
  • 4.6k
  • 4
  • 19

You need the table where you will store the number of occurrences of the char. Then you can print them if that count is larger than 1

void char_counter(char *str) { size_t chars['~'-' ' + 1] = {0,}; // only from ' ' to `~` while(*str) { if(*str >= ' ' && *str <= '~') chars[*str - ' ']++; str++; } for(size_t index = 0; index < sizeof(chars) / sizeof(chars[0]); index++) { if(chars[index] > 1) printf("'%c' - %zu times\n", (char)index + ' ', chars[index]); } } int main(void) { char_counter("dfslgkdjlfk als sdlk sakl jsdakl jsdlkfasdjkfdlgfjgalk!@#@#%$#%^*&^~~~~dfgdf54fdsdd;lfdf;dsfakl3456459657438553985476"); } 

https://godbolt.org/z/hbcvTsMcb