Advertisement
horselurrver

Ch11 Ex4

Aug 8th, 2016
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. char *search(char *string, char *ch);
  4. int main(void){
  5.     char *ptr=search("somehow it's shifted", 'z');
  6.     printf("boop %c\n", *ptr);
  7.     return 0;
  8. }
  9.  
  10. char *search(char *string, char *ch){
  11.     char *ptr=string;
  12.     unsigned long length=strlen(string);
  13.     printf("%lu\n", length);
  14.     unsigned long count=0;
  15.     while (*ptr!=ch){
  16.         ptr++;
  17.         count++;
  18.         if (count==length){
  19.             printf("Character not found in string.\n");
  20.             break;
  21.         }
  22.  
  23.     }
  24.    
  25.     return (ptr);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement