[SOLVED] initializing a multidimensional array of strings
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You can initialize a two-dimensional array; however in my test code I had to put a dimension on the array and specifically place it on the second dimension.
You can initialize a two-dimensional array; however in my test code I had to put a dimension on the array and specifically place it on the second dimension.
Yes, I did mean that. First, I had an incorrect index in my test problem, then a typo in transcribing.
On further testing, the problem solution that I offered earlier really does work. As red as my face is, I will wait a while before I declare that the problem is solved.
Don't -Wall and -Wextra already cover the following ones? I dropped -Wformat=2 into my tmp/Makefile a while ago, I think it was for printf(a_string_variable) cases.
Yes, I find if I'm not copy+pasting directly from tested code, I'm all but guaranteed to make a mistake.
Don't -Wall and -Wextra already cover the following ones? I dropped -Wformat=2 into my tmp/Makefile a while ago, I think it was for printf(a_string_variable) cases.
No -Wall doesn't cover all of those. The documentation for gcc describes what flags are covered by -Wall, in fact -Wformat is covered, but the variations on -Wformat such as =2 is not covered by -Wall.
Easiest two things to do are to look at the manpage for gcc and search for -Wall, but that easily shows what flags are covered. I comprehensive viewing of the flags will show you the list of all flags and when you see ones which you feel are good ideas, you can view the fine print which will say whether or not it is included by -Wall. That second option is what I did a while ago, but it's always worth a continued look.
Cut and paste of a program does work better than transcribing. Baby steps: I am a self-taught C programmer, and compiling with -Wall is not something that I have done before. I will have to study the rest of that list.
The following, using const char, is (IMHO) better than my previous offering:
I don't know the exact code syntax, but C++ is eminently better qualified to manage lists and arrays; similarly is python. For instance, just me tossing it out having not checked, you have a list declared, you also have methods for it such as .size() or .length(), I believe it would be .size() where that will give you an integer representation of the size of the list. Further, the greater part of C++ is that things like String types or something similar; classes actually; allow you to declare something as a String class or list of String classes and not worry about pre-declaring the dimensions. So you might want to keep what you do have, but look a bit at some of the available C++ classes you could use.
And to note further, gcc on a general Linux system should be able to deal with C++ code. Not sure if you're working on that type of platform, but just pointing that detail out.
sizeof(subtopic[i]) returns 8 for all cases of [i]. I do not understand why that is so.
sizeof returns size in bytes, your size[] array is counting the number of elements. subtopic is an array of pointers, all pointers are 8 bytes (or 4 bytes on a 32 bit system).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.