Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- int S(const char *m)
- {
- int k = 0;
- while (*m && *(m + ++k ));
- return k;
- }
- char * copyStr2 (const char * str){
- char * c= (char *)malloc (S(str)+1), *p = c;
- while (*c ++ = *str ++);
- return p;
- }
- char *copyStr(char *str)
- {
- char *copy_str;
- copy_str = (char *)malloc (S(str) + 1);
- int i =0;
- for (i = 0; i < S(str); i++)
- copy_str[i] = str[i];
- return copy_str;
- }
- int main()
- {
- char *STR;
- STR = (char *)malloc (200);
- scanf ("%s", STR);
- char * str2 = copyStr2(STR);
- printf ("%s\n", str2);
- *STR = 'H';
- printf ("%s", str2);
- free ( STR);
- free ( str2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement