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:

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'

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.

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

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)

>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.

>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

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.

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.