Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- void fctMitChar(char * p);
- int main() {
- const char * p1 = "statischer String";
- char * p2 = (char *) malloc( (strlen("dynamischer String") + 1) * sizeof(char) );
- memcpy( p2, "dynamischer String", strlen("dynamischer String") * sizeof(char));
- p2[strlen("dynamischer String")] = '\0'; //terminieren
- printf("%s\n", p1);
- printf("%s\n", p2);
- //statisch darf nicht geschrieben werden deswegen const char * fctMitChar(p1);
- fctMitChar(p2);
- printf("%s\n", p1);
- printf("%s\n", p2);
- return 0;
- }
- void fctMitChar(char * p) {
- size_t len = strlen(p);
- if (strlen("veränderter") < len) {
- memcpy(p, "veränderter", strlen("veränderter") * sizeof(char));
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement