Reputation: 2315
It only prints the description when I print b again after the if statement, really weird behavior, when I remove the last line it doesn't print description is ...
dos anyone know why this happens and how I can fix this? Thanks
char * b;
if (list!= NULL){
b = strdup ( (char *)g_object_get_data(G_OBJECT(list->data), "description") );
printf(" description is %s ", b);
}
printf("\nprinting b: %s\n", b);
Upvotes: 0
Views: 100
Reputation: 182629
It's seems stdout
is line-buffered, i.e. printf
hoards output until it encounters a newline or its buffer fills up. Add a newline to the first printf
:
printf(" description is %s\n", b);
To ensure the output buffer is flushed, you can say:
fflush(stdout);
Upvotes: 1