Advertisement
Guest User

Vjestine_string

a guest
Jun 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5.  
  6. int main(){
  7.  
  8.     char *ime;
  9.     ime=(char*)calloc(50,sizeof(char));
  10.  
  11.  
  12.     scanf("%[^\n]",ime);
  13.  
  14.     int duljina=0;
  15.     int spaceova=0;
  16.     while(*ime!='\0'){
  17.         if(*ime==' '){
  18.             spaceova++;
  19.         }
  20.         ime++;
  21.         duljina++;
  22.     }
  23.     ime-=duljina;
  24.     //printf("%d\n",spaceova);
  25.  
  26.     char*prvi=malloc(sizeof(char)*30);
  27.  
  28.     char*delimiter=" ";
  29.     prvi=strtok(ime,delimiter);
  30.  
  31.     char*rici[10];
  32.     int cnt=0;
  33.  
  34.     printf("%s ",prvi);
  35.  
  36.     int i=0;
  37.     for(i=0;i<10;i++){
  38.         rici[i]=malloc(sizeof(char)*30);
  39.     }
  40.  
  41.     int broj=1;
  42.     while(broj<spaceova+1){
  43.         rici[broj]=strtok(NULL,delimiter);
  44.         broj++;
  45.     }
  46.  
  47.     printf("%s",rici[spaceova]);
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement