Re: Add items to an array



Kevin Walzer wrote:

I'm trying to generate an array of serial numbers for use in an
application. I can get individual serial numbers printed to stdout
using a for loop, but I cannot figure out how to append these numbers
to an array.

char appname[] = "MYAPP";
int serials[20000];

In a higher-level language such as Python I'd do something like this:

serialnumber = ("%s-%i-%i-%i\n", appname, five, eleven, one)
serials.append(serialnumber)

The array serials[] is one containing ints. You have created strings
with non-numeric components (like the app name). What exactly would you
expect this append() to do? You certainly haven't created an int of any
kind. You have a string. Why not an array of strings?




Brian
.



Relevant Pages


Loading