c-playground/string.c

39 lines
984 B
C

#include <stdio.h>
#include <stdlib.h>
int main() {
char *text, c;
int i = 0;
// this returns as a pointer
text = (char*) malloc(1 * sizeof(char));
printf("%p\n", text);
// the size function will print out 8 bytes as it is
// calculating the size of the pointer, not the actual
// value itself. to do that, you gotta dereference it first
size_t size = sizeof(*text);
printf("%d\n", *text);
printf("Size in bytes: %d bytes\n", (int)size);
while(c = getc(stdin), c != '\n') {
text[i] = c;
i++;
printf("===========================================\n");
printf("Num of characters: %d\n", i);
printf("Current char: %c\n", text[i]);
printf("Address of current char: %p\n", &text[i]);
printf("===========================================\n\n");
char* deez = realloc(text, i * sizeof(char));
//printf("%s", deez);
}
printf("The Text: %s\n\n", text);
// size_t size = sizeof(*text);
// printf("Size in bytes: %d bytes\n", (int)size);
return 0;
}