0

hello, ok

here it goes...

I've got a char array but it doesnt want to let me add data to it!! I cant figure out why

//skip the program heres the line...

int chararry[12][10] = {Jan, Feb....}

but I keep getting an error saying its not been initialized... I've tried google but nothing :eek:

5
Contributors
7
Replies
8
Views
12 Years
Discussion Span
Last Post by 1o0oBhP
0

hello, ok

here it goes...

I've got a char array but it doesnt want to let me add data to it!! I cant figure out why

//skip the program heres the line...

int chararry[12][10] = {Jan, Feb....}

but I keep getting an error saying its not been initialized... I've tried google but nothing :eek:

What about the ; behind {}

And 'Jan', 'Feb'

0

Well, but {Jan, Feb} is not 2 strings, but 2 something elses. Enums, variables, something. If you wanted an array of strings, you'd do something more like this:

char* chararry[12] = { "Jan", "Feb", <etc> };

or better yet make it a const char* unless you plan on modifying it.

0

umm! sorry

int chararry[12][10] = {"Jan", "Feb"}

i get the following errors

F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\University work\Computer Science\C++\New Folder\montharray.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast


i sorted it.... But I do hate pointers!!!! Don't understand how to use them

0

Hi Acidburn, change the " to ' Ive tried it out and got the exact error message you got:

C:\Program Files\Microsoft Visual Studio\MyProjects\Testing\Testing.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\Testing\Testing.cpp(14) : error C2440: 'initializing' : cannot convert from 'char [4]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

Testing.obj - 2 error(s), 0 warning(s)
0

>int chararry[12][10] = {"Jan", "Feb"}
Your declaring an array of integers but trying to initialize it with strings. Do you see anything wrong with that? If not then maybe a strongly typed language like C++ isn't your cup of tea.

0

>int chararry[12][10] = {"Jan", "Feb"}
Your declaring an array of integers but trying to initialize it with strings. Do you see anything wrong with that? If not then maybe a strongly typed language like C++ isn't your cup of tea.

yeah i just noticed lol ...damit programming when your tired is not a good way

0

btw a string array would mean you only need a one dimension array:

#include <string> // the string class is in the string library (std name space)
using namespace std;

string months[12] = { "January", "February"...... };

as the lengths are initialised by its constructor. The array is then MUCH easier to work with when you only have a single dimension.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.