Advertisement
horselurrver

Ch11 Ex7

Aug 9th, 2016
289
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 <string.h>
  3.  
  4. char *string_in(char *string1, char *string2);
  5.  
  6. int main(void){
  7.     char *ptr;
  8.     ptr=string_in("flabbergasted", "berg");
  9.     printf("Pointer value: %c\n", *ptr);
  10.     return 0;
  11. }
  12.  
  13. char *string_in(char *string1, char *string2){
  14.     char *ptr1=string1;
  15.     char *ptr2=string2;
  16.     int i, x;
  17.     for(i=0; i<(int)strlen(string1); i++){
  18.         ptr1++;
  19.         ptr2++;
  20.         if (*ptr1==*ptr2){ //if first letter matches
  21.             for(x=i; x<(int)strlen(string1); x++){ //check other letters
  22.                 ptr1++;
  23.                 ptr2++;
  24.                 if(*ptr1!=*ptr2)
  25.                     break;
  26.             }
  27.         }
  28.     }
  29.     return (ptr1+1);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement