fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct _char_count {
  6. char c;
  7. int count;
  8. struct _char_count *next;
  9. } char_count;
  10.  
  11.  
  12. int main(int argc, char **argv){
  13. int i, j;
  14. char_count *headptr, *tmp, *prev;
  15.  
  16. tmp = NULL;
  17. prev = NULL;
  18. headptr = NULL;
  19.  
  20. for (i=1; i < argc; i++) {
  21. for (j=0; j < strlen(argv[i]); j++){
  22. tmp = headptr;
  23. while (1) {
  24. if(tmp == NULL){
  25. tmp = (char_count *) malloc(sizeof(char_count));
  26. tmp->c = argv[i][j];
  27. tmp->count = 1;
  28. tmp->next = NULL;
  29. if (headptr == NULL) {
  30. headptr = tmp;
  31. } else {
  32. prev->next = tmp;
  33. }
  34. break;
  35. }
  36. else if (tmp->c == argv[i][j]) {
  37. tmp->count++;
  38. break;
  39. }
  40. else {
  41. prev = tmp;
  42. tmp = tmp->next;
  43. }
  44. }
  45. }
  46. }
  47.  
  48. for (tmp = headptr; tmp !=NULL; tmp = tmp->next){
  49. printf("%c - %d\n", tmp->c, tmp->count);
  50. }
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty