c - Arrays to Linked Lists -


this in c.

i have take information command line (ex. ./command # # #)then run information through command , print subsequent information.

int *numbers = malloc(sizeof(argc)*sizeof(int)); int = 0; while (i<argc) {     numbers[i] = atoi(argv[i+1]);     i++;    }  node *a = arraytolist(numbers,sizeof(numbers)/sizeof(int)); node *b = maplist(decrement,a); displaylist(b);  return 0; 

it meant return values 1 less, struggling have numbers read original array.

any ideas?

the first part of code should be

if ( argc < 2 )     exit( 1 );     // need @ least 1 arg after command name  int numbers[argc-1]; ( int = 1; < argc; i++ )     numbers[i-1] = atoi(argv[i]); 

you need allocate space ints, , process args 1 argc-1.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -