Advertisement
horselurrver

Ch11 Ex3

Aug 8th, 2016
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. int num=0;
  4. char *firstword(char *string, char array[]);
  5. int main(void){
  6.     char *ptr;
  7.     char array[40];
  8.     ptr=firstword("hello how are you?", array);
  9.     while(*ptr){
  10.         printf("%c", *ptr);
  11.         ptr++;
  12.     }
  13.     printf("\n");
  14.     return 0;
  15. }
  16.  
  17. char *firstword(char *string, char array[]){
  18.     char *ptr=string;
  19.     char *ptr2=array;
  20.  
  21.     int i;
  22.     while(!isspace(*ptr)){
  23.         *ptr2=*ptr;
  24.         ptr2++;
  25.         ptr++;
  26.         num++;
  27.     }
  28.     *ptr2='\0';
  29.     for(i=0; i<num; i++){
  30.         ptr2--;
  31.     }
  32.    
  33.     return ptr2;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement