Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int **test(char *tab)
  6. {
  7.     int **a = malloc(sizeof(int*) * 2);
  8.     int b = 0;
  9.  
  10.     a[0] = &tab[0];
  11.     b++;
  12.     for (int i = 0; tab[i] != '\0'; i++) {
  13.         if (tab[i] == 42){
  14.             a[b] = &tab[i + 1];
  15.         }
  16.     }    
  17.     return (a);
  18. }
  19.  
  20. void print(int **a, int nbr)
  21. {
  22.     for (int j = 0; j < nbr; j++) {
  23.         printf("%c\n", *a[j]);
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.     char *tab = malloc(sizeof(char) * 1024);
  30.     int **ptr;
  31.     scanf("%s", tab);
  32.     //printf("%s %c\n", tab, tab[0]);
  33.     ptr = test(tab);
  34.     print(ptr, 2); // faire le test avec 2 étoile car j'avais pas l'autre tp poour le config
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement