RE: [Dev-C++] char Array - DevC++ beginner...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <a_g...@ya...> - 2003-06-16 19:51:06
|
another thing. it should be
Name[1]='J';
and not
Name[1]="J";
cause "J" is a string by itself. It should be 'J' which is treated as a character constant.
Abhijit Shylanath <mu...@gm...> wrote:
Greets, Janine.
> char Name[];
> Name[1]="J";
When creating an array, you need to specify the size. An exception is when
you're specifying the array elements alongside (or when you're allocating
memory dynamically, but that would be called a pointer, not an array).
Also, a char is represented using single-quotes. So "J" is wrong. 'J' is
right. When you use double-quotes, the compiler sees it as an array of
chars, terminated by a null chracter (\0).
So,
"foo"
is the same as
{'f', 'o', 'o', '\0' }
or
{'f', 'o', 'o', 0 }
In the above program, use
char Name[25]; // Some arbitrary size, otherwise, do char Name[] = "foo";
Name[1] = "J";
and it should work. One more thing - arrays begin at zero. I suspect that
here, you're trying to access the first element, in which case, it would be
Name[0].
HTH.
________________________________________
Abhijit Shylanath
http://mudeth.tripod.com/
-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
Thanx and Regards
Avik Ghose
SMS using the Yahoo! Messenger;Download latest version. |