So i am going to do some string manipulation, but when i try to print out what my pointer is pointing to at time time, i get really weird output.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (){
size_t n = 10;
char *mystring = malloc(10);
int line = 0;
int tokens = 0;
char *ptr;
if(mystring==NULL){
fprintf(stderr, "No memory\n");
exit(1);
}
while(getline(&mystring, &n, stdin)>0){
printf("len = %lu, mystring = %s\n", strlen(mystring), mystring);
printf("let's tokenize this string\n line = %d tokens = %d\n", line, tokens);
ptr = mystring;
printf("ptr = %ch\n", ptr[0]);
}
return 0;
}
This is what my output looks like when i enter hello
len = 6, mystring = hello
let's tokenize this string line = 0 tokens = 0
ptr = hh
what's with the double hh?