Advertisement
Guest User

Untitled

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