JamesPoppycock JamesPoppycock - 4 months ago 10
C Question

C char array storing a variable

I would like to store 2 variables into char array, and print our the first one as shown below.

const char *a[2];
a[0] = getCapital(bufferStore); //"Australia"
a[1] = getCurrencyCode(bufferStore); "9876.00"

printf("%s", a[0]);

However, I did not get any output. The code of getCapital and getCurrencyCode should be redundant here. The main thing I want to find out is how I can print out "Australia". I'm new to C language and pointers are really hard to understand, and my assignment is due in 2 hours. Any help will be greatly appreciated!


The file stdout, which is what printf writes to, is by default line buffered. That means everything you write to it is buffered, i.e. stored in memory, and is flushed (and actually printed) when you print a newline.