Hello there, guys!
I am relatively new to programming in C, and I still have a lot to learn. I am currently using Dev C++, but I work in C only. My problem is that I need to fill a 2D table with some multi-character variables, and I don't know how to declare one. I declared the table as char, but only the it was initiated only to the first value I gave, not all of them. I mean, if I put "HELLO", it would contain only "H".
I was thinking, would it be wise to use a 3D table, and use its third dimension as the maximum character length of the strings I want to use? I know this would entail a lot more work, and I hope there is another way. If anyone can help me, please do so! I will be forever grateful!
Please, reply ASAP!
- ShadowHawk
Zababa
0
Newbie Poster
Recommended Answers
Jump to PostThis works:
int main(int argc, char *argv[]) { char table[5][10]={"Hello","Hello","Hello","Hello","Hello"}; int i=0; for(i=0;i<5;i++) { printf("%d %s\n",i,table[i]); } return 0; }
Also, don't compile C under a C++ compiler, if you can avoid it,
you will get some odd results.
All 3 Replies
Reply to this topic
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.