Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. char** fkt(char *str, int *a)
  4. {
  5.     int wrs=1, x=0, y;
  6.      for(int i=0; str[i]!='\0';i++)
  7.     {
  8.         if(str[i]==' ')wrs++;
  9.     }
  10.     char **tab2=malloc(wrs*sizeof(char*));
  11.     wrs=0;
  12.      for(int i=0; str[i]!='\0';i++)
  13.     {
  14.         if(str[i]==' ')
  15.         {
  16.             y=i;
  17.             char*tab1=malloc(y-x+1);
  18.             for(int j=x; j<y;j++)tab1[j-x]=str[j];
  19.             tab1[y-x]='\0';
  20.             tab2[wrs++]=tab1;
  21.         }
  22.     }
  23.     a=wrs-1;
  24.     return tab2;
  25.  
  26. }
  27.  
  28. int main(void)
  29. {
  30.     char tab[]="ala ma kota";
  31.     int wsk;
  32.     char **wyn=fkt(tab,&wsk);
  33.     for (int i=0; i<wsk;i++)
  34.     {
  35.         printf("%s ",tab[i]);
  36.     }
  37.  
  38.      return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement