Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. void fctMitChar(char * p);
  7.  
  8.  
  9. int main() {
  10.         const char * p1 = "statischer String";
  11.         char * p2 = (char *)  malloc( (strlen("dynamischer String") + 1) * sizeof(char) );
  12.         memcpy( p2, "dynamischer String", strlen("dynamischer String") * sizeof(char));
  13.  
  14.         p2[strlen("dynamischer String")] = '\0'; //terminieren
  15.  
  16.         printf("%s\n", p1);
  17.         printf("%s\n", p2);
  18.  
  19.         //statisch darf nicht geschrieben werden deswegen const char * fctMitChar(p1);
  20.         fctMitChar(p2);
  21.  
  22.         printf("%s\n", p1);
  23.         printf("%s\n", p2);
  24.  
  25.         return 0;
  26. }
  27.  
  28. void fctMitChar(char * p) {
  29.         size_t len = strlen(p);
  30.  
  31.         if (strlen("veränderter") < len) {
  32.                 memcpy(p, "veränderter", strlen("veränderter") * sizeof(char));
  33.         }
  34.  
  35.         return;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement