Advertisement
horselurrver

Ch11 Ex5

Aug 8th, 2016
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int is_within(char ch, char string[]);
  5. int main(void){
  6.     printf("The number is %d.\n", is_within('h', "hello"));
  7.    
  8.     return 0;
  9. }
  10.  
  11. int is_within(char ch, char string[]){
  12.     int instring=0; //false
  13.     unsigned long length=strlen(string);
  14.     unsigned long count=0;
  15.     char *ptr=string;
  16.     while(count!=length){
  17.         if(*ptr==string[count])
  18.             instring=1;//true
  19.             break;
  20.         ptr++;
  21.         count++;
  22.     }
  23.     return instring;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement