Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4.  
  5. int S(const char *m)
  6. {
  7.     int k = 0;
  8.     while (*m && *(m + ++k ));
  9.     return k;
  10. }
  11.  
  12. char * copyStr2 (const char * str){
  13.     char * c= (char *)malloc (S(str)+1), *p = c;
  14.     while (*c ++ = *str ++);
  15.     return p;
  16. }
  17.  
  18. char *copyStr(char *str)
  19. {
  20.     char *copy_str;
  21.     copy_str = (char *)malloc (S(str) + 1);
  22.     int i =0;
  23.     for (i = 0; i < S(str); i++)
  24.         copy_str[i] = str[i];
  25.     return copy_str;
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     char *STR;
  32.     STR = (char *)malloc (200);
  33.     scanf ("%s", STR);
  34.     char * str2 = copyStr2(STR);
  35.     printf ("%s\n", str2);
  36.     *STR = 'H';
  37.     printf ("%s", str2);
  38.     free ( STR);
  39.     free ( str2);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement