Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define NO_ERROR 0
- #define NULL_PTR_ERROR -1
- typedef char * String;
- String stringConstructor(int length) {
- String newString = (String) malloc(sizeof(char) * length + 1);
- newString[length] = 0; //null terminate just in case
- return newString;
- }
- int stringSet(String this, char * string) {
- if (this==NULL) return NULL_PTR_ERROR;
- strcpy(this, string);
- return NO_ERROR;
- }
- int main(void) {
- int error_code =0;
- String a_string = stringConstructor(64);
- error_code = stringSet(a_string, "Hello world");
- if (error_code) {
- printf("Error - not a valid pointer\n");
- }
- else printf("%s\n", a_string);
- }
Add Comment
Please, Sign In to add comment