Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- bool is_equal(char *a, char *b) {
- int c = strlen(a);
- for (int i = 0; i <= c; i++)
- if (a[i] != b[i])
- return false;
- return true;
- }
- int main(void) {
- char d[30][11];
- int n = 0;
- printf("Enter the string:\n");
- while (1) {
- char c;
- int i = 0;
- while (1) {
- c = getchar();
- if (c == ',' || c == '.') {
- d[n][i] = '\0';
- break;
- }
- d[n][i] = c;
- i++;
- }
- if (c == '.')
- break;
- }
- printf("Words and their number:\n");
- for (int i = 0; i <= n; i++) {
- bool flag = true;
- int cnt = 0;
- for (int j = 0; j <= n; j++) {
- if (is_equal(d[i], d[j])) {
- if (i < j) {
- flag = false;
- break;
- }
- cnt++;
- }
- }
- if (flag)
- printf("%s %d\n", d[i], cnt);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement