Bill Cunningham said:
Ian Collins said:
The how about
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv )
{
double data[4] = {0.0};
if ( argc > 5 ) {
puts("Too many arguments");
exit(EXIT_FAILURE);
}
unsigned n = 1;
while ( n < argc ) {
data[n-1] = strtod(argv[n], NULL);
++n;
[snip]
What's above is a bit of a different method than I would think of. Is that n
minus 1 in the brackets?
Why set n to 1?
Bill
To confuse you I assume. Its not a very C way of doing it IMO. Not
tested for ISO C correctness or whether it even works but this is much
clearer if you (and you must as a c programmer) understand for
loops. You should get the idea.
for(int n=0;n<argc;n++)
data[n] = strtod(argv[n+1], NULL);