Re: char array question

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 08/07/04


Date: Sat, 07 Aug 2004 06:18:27 +0100

On Fri, 06 Aug 2004 18:42:55 -0400, ali <tj@raha.com> wrote:

> Hi,
>
> I'm having a problem understanding the reason for output on the
> following code:
>
> #include <iostream.h>
>
> int main()
> {
>
> char array[]={'w','e','l','c','o','m','e'};
>
> cout<<array<<endl;
>
> return 0;
> }
>
> When i run this, the output is something like this:
>
> welcome¦+ ?
>
> Will appreciate some help on understanding the concept.
>
> Thanks,
>
> ali

Change your array to this

        char array[]={'w','e','l','c','o','m','e','\0'};

or this

        char array[]="welcome";

Those are two different ways to add the nul terminateor that everyoe else
has told you about.

john



Relevant Pages

  • Re: char array question
    ... "ali" wrote in message ... > I'm having a problem understanding the reason for output on the ... > int main ...
    (comp.lang.cpp)
  • Re: incrementing records in linked subform
    ... (if you wouldn't mind). ... i'm having a small problem understanding the ... calligraphy and i know it'd be simpler to just cut and paste the finished ... product and then worry about understanding the reason it works. ...
    (microsoft.public.access.modulesdaovba)
  • Re: char array question
    ... > I'm having a problem understanding the reason for output on the ... > int main ... This is character ...
    (comp.lang.cpp)
  • Re: char array question
    ... ali wrote: ... > I'm having a problem understanding the reason for output on the ... > int main ...
    (comp.lang.cpp)
  • Re: convolution problem
    ... > I have a problem understanding the transition between and at ... > the actual problem that concerns me, but the reason for it troubling me is ... Jon ...
    (sci.math)