Solved

An easy string-array question

Posted on 2000-04-11
3
182 Views
Last Modified: 2010-04-02
I´m getting on the run with C and I need a tip for this. (Well, I think pointers and arrays in C are dificult to understand in the first days of training)

I have this declaration :

char strings[50][2];

Then.. how can I store values in this array that makes it look like this ?

 strings[1] = 'nel'
 strings[2] = 'sol'
 strings[3] = 'xel'

I can´t change the declaration to a similar one because I have some restrictions in PRO*C/C++ for Oracle, So the next declaration wont work:

 char *strings[3]   ---> This not good

And I need access the value in this way

  printf("\n",strings[1]);

I need also use (if I need to) compatible UNIX functions.

Regards!

0
Comment
Question by:NetoMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
inpras earned 25 total points
ID: 2705826
Hi
use it like this
char strings[50][50];
strcpy(strings[1], "nel");
strcpy(strings[1], "sol");
strcpy(strings[1], "xel");
Hope this helps
0
 
LVL 2

Author Comment

by:NetoMan
ID: 2705906
Well... I´already tried that and didn´t work but in the run I notice that I have a error on my code :

char strings[50][2]

strings[1] = 'nel'
strings[2] = 'sol'
strings[3] = 'xel'

and when Im doing :

  strcpy(strings[1], "xel");

it didn´t work because of the difference in th length in 'xel' and the declaration of strings.

The point in here is why C does´nt check this insetad of writing in the strings :

strings[1] = 'nelsolxel'
strings[2] = 'nelsol'
strings[3] = 'xel'

well... that´s another question.

inpras : I´ll give you points in a grade C because I resolve my problem on my own but apreciate your help.
0
 
LVL 4

Expert Comment

by:inpras
ID: 2705972
coming to answer of UR another question C being very flexible in pointers it won't check for array upper bounds ofcourse richie could have implemented it very easily but as U go on mastering it U will feel the advantages of it.
like accessing memory direcly and so on
Hope I cleared a little what doubt of URs
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question