I'm writing a C program that accepts a list of unsigned long long
numbers as input from the command line. How do I parse them and store in an array? It seems that strtoull
might help, but how do I use it?
Here is my code:
#include<stdio.h>
main (int argc, char *argv[])
{
unsigned long long M[1000];
int i;
printf("length: %d\n", argc - 1);
for(i = 1; i < argc; i++) {
M[i] = strtoull(argv[i], NULL, 10);
printf("%llu\n", M[i]);
}
return 0;
}
It works when parameters are small, but when I enter a huge number (say, 123456789012345), it is not parsed correctly. What am I doing wrong?