Hy everybody, I really can't figure out why this code I wrote is not working. I need to store in an array the integers passed through the command line after the name of a file to open. The code is the following:
void read(int **a, int argc, char *argv[]) {
int i;
char temp[20];
if((*a = malloc(sizeof(int) * (argc - 2))) == NULL){
fprintf(stderr, "Error.\n");
exit(-1);
}
for (i = 2; i < argc; i++){
strcpy(temp, argv[i]);
**(a + i - 2) = atoi(temp);
}
}
Can anybody help please? Thanks a lot!