Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int strlen1(char *st) {
  6.     int length;
  7.     length = 0;
  8.     while (*st != '\0') {
  9.         length++;
  10.         st++;
  11.     }
  12.     return length;
  13. }
  14.  
  15. char *strcpy1( char *target , char *source ){
  16.     while ((*target = *source) != '\0'){
  17.         target++;
  18.         source++;
  19.     }
  20. return target;
  21. }
  22.  
  23. int *strstr1( char *string1, char *pattern) {
  24.     int flag1 = 0;
  25.     int i = 0;
  26.     int k = 0;
  27.     int j = 0;
  28.  
  29.     for (;*string1 != '\0';string1++){
  30.         i++;
  31.             for( j = 0; *(string1+j) == *(pattern+j); j++);
  32.         if (*(pattern+j) == '\0') {
  33.             flag1 = 1;
  34.             k = i;
  35.             break;
  36.         }
  37.     }
  38.  
  39.     if (flag1 == 1) {
  40.         return k ;
  41.     } else {
  42.         return -1;
  43.     }
  44. }
  45.  
  46. int main(){
  47.     char *st, *source, *target, *string1, *pattern;
  48.     int k;
  49.     int c;
  50.     source = "cat";
  51.     target = "dog";
  52.     strcpy1(target, source);
  53.     c = strlen1("abcdf");
  54.     printf("%d \n", c);
  55.     printf("%s", target);
  56.     k = strstr1("hello, world", "world");
  57.     printf("%d \n", k);
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement