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.
Here is my code:
#include <stdio.h>
int main (void) {
int i;
int count = 20000;
char appname[] = "MYAPP";
int serials[20000];
for (i = 1; i < count; ++i) {
int five = i*5;
int eleven = i/11;
int one = (i-1);
printf("%s-%i-%i-%i\n", appname, five, eleven, one);
}
return 0;
}
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)
but I'm not sure how to assign this kind of value to a C variable, nor
am I sure how to populate the C array with this value. Any advice is
appreciated.
--
Kevin Walzer
Code by Kevin
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.
Here is my code:
#include <stdio.h>
int main (void) {
int i;
int count = 20000;
char appname[] = "MYAPP";
int serials[20000];
for (i = 1; i < count; ++i) {
int five = i*5;
int eleven = i/11;
int one = (i-1);
printf("%s-%i-%i-%i\n", appname, five, eleven, one);
}
return 0;
}
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)
but I'm not sure how to assign this kind of value to a C variable, nor
am I sure how to populate the C array with this value. Any advice is
appreciated.
--
Kevin Walzer
Code by Kevin
Comment