#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
int fir; //badly named loop variable
char *input[] = calloc( strlen(argv), sizeof(char)); //initializing an array
for( fir = 1; fir< strlen(argv); fir++){ //removing the first element of argv
strcat(input, argv[fir]); // appending to input
}
}
The error I'm getting is for line 7. It says "passing argument 1 of 'strlen' from incompatible pointer type". I get the same error for the strcat
function.
It also says "given a char **
but expected a const char *
" for both functions.
I'm trying to populate a new array with all the elements of argv
except the first. I tried argv = &argv[1]
and it did not work.
Do the strlen()
and strcat()
functions not take char
arrays?
argv[]
, but don't go outside[0..(argc-1]
when you do. – Cydnus