views:

165

answers:

1

hi,

I was using C to display a sentence in three lines. The piece of code which worked successfully in VC++ is giving an unexpected output in Borland C++. The ouptut is a charcter array of size n. In the output I could receive more than n characters for the array. How can I avoid this?

+1  A: 

There needs to be an array element that is '\0', otherwise the string is not NULL-terminated and you get garbage printed out. It was pure luck it worked in VC++.

Probably because VS defaults to debug mode where memory is initialized to zeros.
Ofir