Advertisement
thienlang

pointer

Mar 13th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. int coutword(char* s[],char chuoi[], char * temp){
  6.  
  7.      int nword=0;
  8.  
  9.      char* sep=" ;:,./\t\n";
  10.      strcpy(temp,chuoi);
  11.      char* word=strtok(temp,sep);
  12.      while(word!=NULL){                
  13.          s[nword] = word;
  14.          nword++;
  15.          word=strtok(NULL,sep);                                        
  16.      }
  17.  
  18.      return nword;
  19. }
  20. int main(){
  21.     char *s [100];
  22.      for ( int i = 0 ; i < 100; i++)
  23.      {
  24.          *s = new char[100];
  25.      }
  26.      char chuoi[]="Ton That Anh";
  27.      char* temp=new char[strlen(chuoi)+1];
  28.      int count=coutword(s,chuoi,temp);
  29.      for(int i=0;i<count;i++){
  30.              printf("%s\t",s[i]);        
  31.      }
  32.      getch();
  33.      delete []s;
  34.      delete []temp;
  35.      return 1;    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement