Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int strlen1(char *st) {
- int length;
- length = 0;
- while (*st != '\0') {
- length++;
- st++;
- }
- return length;
- }
- char *strcpy1( char *target , char *source ){
- while ((*target = *source) != '\0'){
- target++;
- source++;
- }
- return target;
- }
- int *strstr1( char *string1, char *pattern) {
- int flag1 = 0;
- int i = 0;
- int k = 0;
- int j = 0;
- for (;*string1 != '\0';string1++){
- i++;
- for( j = 0; *(string1+j) == *(pattern+j); j++);
- if (*(pattern+j) == '\0') {
- flag1 = 1;
- k = i;
- break;
- }
- }
- if (flag1 == 1) {
- return k ;
- } else {
- return -1;
- }
- }
- int main(){
- char *st, *source, *target, *string1, *pattern;
- int k;
- int c;
- source = "cat";
- target = "dog";
- strcpy1(target, source);
- c = strlen1("abcdf");
- printf("%d \n", c);
- printf("%s", target);
- k = strstr1("hello, world", "world");
- printf("%d \n", k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement