Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct node{
  4.     int val;
  5.     struct node * next;
  6. }node_t;
  7.  
  8. void makeLinkedLists(node_t* P[], char Tab[][12]){
  9.     for(int i = 0; i < 12; i++){
  10.         int j = 1;
  11.         node_t * last = (node_t*) malloc(sizeof(node_t));
  12.         last->val = Tab[i][0];
  13.         while(Tab[i][j] != '\0'){
  14.             node_t * character = (node_t*) malloc(sizeof(node_t));
  15.             last->next = character;
  16.             character -> val = Tab[i][j];
  17.             last = character;
  18.             j++;
  19.         }
  20.         last->next = NULL;
  21.     }
  22. }
  23.  
  24. int count_a(char Tab[][12]){ //zliczanie 'a' w tablicy 2-wymiarowej
  25.     int score = 0;
  26.     for (int i = 0; i < 12; i++){
  27.         int j = 0;
  28.         while(Tab[i][j] != '\0'){
  29.             if(Tab[i][j] == 'a')
  30.                 score++;
  31.             j++;
  32.         }
  33.     }
  34.     return score;
  35. }
  36.  
  37. int count_aInList(node_t* P[]){ //zliczanie 'a' w tablicy wskaznikow do lancuchow
  38.     int score = 0;
  39.     for(int i = 0; i < 12; i++){
  40.         node_t* character;
  41.         character = P[0];
  42.         while(character != NULL) {
  43.             if (character->val == 'a')
  44.                 score++;
  45.             character = character->next;
  46.         }
  47.     }
  48.     return score;
  49. }
  50.  
  51. int main() {
  52. int* T[10]; //tablica wskaznikow
  53. int *p = T; // wskaznik na pierwszy element tablicy
  54.  
  55. char Tab[12][12] = {"Styczen", "Luty", "Marzec", "Kwiecien", "Maj", "Czerwiec",
  56.                     "Lipiec", "Sierpien", "Wrzesien", "Pazdziernik", "Listopad", "Grudzien"};
  57.  
  58. node_t *P[12];
  59.  
  60. printf("%d", count_a(&Tab));
  61. makeLinkedLists(P, Tab);
  62. //printf("\n%d", count_aInList(Tab));
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement