My array keeps outputting this random character (kind of like a # in a box). Anyways, its just garbage really, but how do i stop it from doing this.

If my array was like

char title[10]

and the user inputted something with only 5 characters, then the remaining characters would be the garbage character.

How do I stop this?

set some default value to them such as 0

Are you outputting array with a loop?If so, try putting the condition


Initialize the array by flooding it with all 0s. char title[10] = {0};

I believe I know why, although I am not positive. Anyway, my guess would be that the [10] is only initializing the amount of characters you can have in the word. Therefore, in order to have it as an array you would need:

char title[10][25]

This works for me anyway..

@ancientdragon, wouldn't he need quotes around the character to initialize it? Not positive if you do or not..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.