473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Arrays

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;
Nov 14 '05 #1
16 2620
Neil Fallon wrote:

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);

--
pete
Nov 14 '05 #2
Hi Pete,

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

Neil

"pete" <pf*****@mindspring.com> wrote in message
news:40***********@mindspring.com...
Neil Fallon wrote:

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);

--
pete

Nov 14 '05 #3
Neil Fallon <nf****@comcast.net> scribbled the following:
Hi Pete, 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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
Nov 14 '05 #4
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

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bu**********@oravannahka.helsinki.fi...
Neil Fallon <nf****@comcast.net> scribbled the following:
Hi Pete,

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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran

Nov 14 '05 #5
Neil Fallon wrote:

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
Nov 14 '05 #6

"Default User" <fi********@boeing.com.invalid> wrote in message
news:40***************@boeing.com.invalid...
Neil Fallon wrote:

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


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
Nov 14 '05 #7
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 fuck yourself. I'm
off this forum.

Neil

"Neil Fallon" <nf****@comcast.net> wrote in message
news:w7eQb.104689$Rc4.711554@attbi_s54...

"Default User" <fi********@boeing.com.invalid> wrote in message
news:40***************@boeing.com.invalid...
Neil Fallon wrote:

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


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

Nov 14 '05 #8
"Neil Fallon" <nf****@comcast.net> wrote in message news:<OC8Qb.105267$sv6.503992@attbi_s52>...

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.
Nov 14 '05 #9
Neil Fallon wrote:
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
Nov 14 '05 #10
Neil Fallon wrote:

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 fuck 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
Nov 14 '05 #11
Neil Fallon wrote:
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 fuck 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.

Nov 14 '05 #12
"E. Robert Tisdale" wrote:
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
Nov 14 '05 #13
Neil Fallon wrote:
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.

Nov 14 '05 #14
Neil Fallon <nf****@comcast.net> scribbled the following:
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.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"How come even in my fantasies everyone is a jerk?"
- Daria Morgendorfer
Nov 14 '05 #15
Default User wrote:
Neil Fallon wrote:

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


Does mooning count?

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #16
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 fuck 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"?
Nov 14 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.