Arrays

N

Neil Fallon

Hi,

I'm new to C and having some problems passing a string to an array. I don't
know if I can do a direct assignment. I have a string (make) that I would
like to add to the array (itemList). itemList should be an array of 150
items. When I try to do a direct assignment the debugger tells me that I am
trying to pass a null string. If I display what is in make it has the data
there.

Neil


Char itemList[150];

itemList[0] = make;
 
P

pete

Neil said:
Hi,

I'm new to C and having some problems passing a string to an array. I don't
know if I can do a direct assignment. I have a string (make) that I would
like to add to the array (itemList). itemList should be an array of 150
items. When I try to do a direct assignment the debugger tells me that I am
trying to pass a null string. If I display what is in make it has the data
there.

Neil

Char itemList[150];

itemList[0] = make;

#include <string.h>

strcpy(itemList, make);
 
N

Neil Fallon

Hi Pete,

When I try that I'm getting passing arg 1 of strcpy makes pointer from
integer without a cast.

Neil



pete said:
Neil said:
Hi,

I'm new to C and having some problems passing a string to an array. I don't
know if I can do a direct assignment. I have a string (make) that I would
like to add to the array (itemList). itemList should be an array of 150
items. When I try to do a direct assignment the debugger tells me that I am
trying to pass a null string. If I display what is in make it has the data
there.

Neil

Char itemList[150];

itemList[0] = make;

#include <string.h>

strcpy(itemList, make);
 
J

Joona I Palaste

Neil Fallon said:
When I try that I'm getting passing arg 1 of strcpy makes pointer from
integer without a cast.

Make sure you have the #include <string.h>, and you have the correct
declarations for itemList and make. itemList is char itemList[150],
right? Is make char *make?
Char itemList[150];

itemList[0] = make;

#include <string.h>

strcpy(itemList, make);
 
N

Neil Fallon

Yes, I have those set right. I think the problem is that I'm working on the
Palm platform with GCC. There is no string.h in Palm. The strcpy on is
actually StrCopy. I'm getting the make from a database and trying to pass
it to an array. To get make from the database I'm doing the following which
gives me the data:

make = MemPtrNew(StrLen(ptr)+1);
StrCopy(make,ptr);
ptr += StrLen(ptr)+1;


When your new to C and ask C questions in the Palm forums they tell you to
read a C book. That's why I am asking the question here. I've read the C
books and some things still doesn't make sense.



Neil



Neil Fallon said:
When I try that I'm getting passing arg 1 of strcpy makes pointer from
integer without a cast.

Make sure you have the #include <string.h>, and you have the correct
declarations for itemList and make. itemList is char itemList[150],
right? Is make char *make?
Char itemList[150];

itemList[0] = make;

#include <string.h>

strcpy(itemList, make);

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
 
D

Default User

Neil said:
Hi Pete,

When I try that I'm getting passing arg 1 of strcpy makes pointer from
integer without a cast.

1. Please don't top-post. Your replies belong following properly trimmed
quotes.

2. When you have questions, show us the complete code that you are
having problems with. Otherwise we spend time speculating about what you
may have left out.




Brian Rodenborn
 
N

Neil Fallon

Default User said:
1. Please don't top-post. Your replies belong following properly trimmed
quotes.

2. When you have questions, show us the complete code that you are
having problems with. Otherwise we spend time speculating about what you
may have left out.




Brian Rodenborn

Hi Brian

Sorry for the top posting. IE put the cursor there automatically. It was
my first time posting here and didn't know that there was a rule against it.

Neil
 
N

Neil Fallon

You know, on second thought. Brian you're a dick head and if I had you in
front of me right now I'd punch the shit out of you. Go **** yourself. I'm
off this forum.

Neil
 
J

J. J. Farrell

Neil Fallon said:
I'm new to C and having some problems passing a string to an array. I don't
know if I can do a direct assignment. I have a string (make) that I would
like to add to the array (itemList). itemList should be an array of 150
items. When I try to do a direct assignment the debugger tells me that I am
trying to pass a null string. If I display what is in make it has the data
there.

Char itemList[150];

itemList[0] = make;

Your description is not entirely clear. Others have interpreted your
question as wanting to copy the contents of 'make' into 'itemList'
so that 'itemList' is the same as 'make'. I'm guessing that you
want your 'itemList' to be a list of up to 150 strings like 'make'.
If I'm correct, your error is in the definition of 'itemList'.
You want something along the following lines:

char *itemList[150];

itemlist[0] = make;
itemlist[1] = anotherString;

You should perhaps also consider how you will know that a particular
entry in 'itemList' currently points to a string. The normal way to
avoid confusion in this area is to make sure that every entry in
'itemList' is initialized to a null pointer before you start filling
it. This can usually be done where the list is defined:

#include <stddef.h>

char *itemList[150] = { NULL };

You can subsequently check if an entry has been filled in yet by
comparing its value to NULL.
 
D

Default User

Neil said:
Sorry for the top posting. IE put the cursor there automatically. It was
my first time posting here and didn't know that there was a rule against it.


There's actually a patch for outlook to not do that, I believe. We like
it (bottom-posting) because promotes clarity of expression, and we're
all about the clarity thing. Except for Trollsdale.



Brian Rodenborn
 
E

E. Robert Tisdale

Neil said:
You know, on second thought.
Brian you're a dick head and
if I had you in front of me right now,
I'd punch the shit out of you.
Go **** yourself.
I'm off this forum.

I see that you've met one of out indigenous trolls.
If you decide to stick around,
you will begin to recognize them and learn to ignore them.
 
D

Default User

Neil said:
You know, on second thought. Brian you're a dick head and if I had you in
front of me right now I'd punch the shit out of you. Go **** yourself. I'm
off this forum.


Aw. I even said "please" too.


Let's see a show of hands of those that will miss Neil.



Brian Rodenborn
 
D

Default User

:
I see that you've met one of out indigenous trolls.


Hi Trollsdale! I'm surprised you passed up the chance to give the
departing Neil some bogus advice before he left.




Brian Rodenborn
 
I

I.M.A Troll

Neil said:
if I had you in front of me right now I'd punch the shit out of you.

Or hit him with your Palm Pilot. Since you can't program it, why
not use it as a weapon.
 
J

Joona I Palaste

Neil Fallon said:
Yes, I have those set right. I think the problem is that I'm working on the
Palm platform with GCC. There is no string.h in Palm. The strcpy on is
actually StrCopy. I'm getting the make from a database and trying to pass
it to an array. To get make from the database I'm doing the following which
gives me the data:
make = MemPtrNew(StrLen(ptr)+1);
StrCopy(make,ptr);
ptr += StrLen(ptr)+1;
When your new to C and ask C questions in the Palm forums they tell you to
read a C book. That's why I am asking the question here. I've read the C
books and some things still doesn't make sense.

I would have offered more advice, but after seeing your reply to Default
User, I will just ask you to either apologise or get the hell out of
comp.lang.c.
 
P

Peter Shaggy Haywood

Groovy hepcat Neil Fallon was jivin' on Fri, 23 Jan 2004 20:24:09 GMT
in comp.lang.c.
Re: Arrays's a cool scene! Dig it!
You know, on second thought. Brian you're a dick head and if I had you in
front of me right now I'd punch the shit out of you. Go **** yourself. I'm
off this forum.

Good ridance (sp?) to a foul mouth! And good luck getting help next
time you need it.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,797
Members
47,344
Latest member
KamCrowthe

Latest Threads

Top