So, I understand you're new to programming, but surely this looks familiar, no?
int main (int argc, char **argv) {
// ...
}
char **argv is a pointer to a char pointer, but for your purposes, you can consider it to be the equivalent of char *argv[]. The difference is subtle, but worth noting, since this caveat is vital to understanding the way strings work in C. char *argv[] is explicitly typed as an array of char pointers, while char **argv could be an array but you wouldn't know until you try to access it as such. Given that it's your main function, it's safe to assume this will always be instantiated appropriately.
Anyway, moving past the tangent, we have an array of null-terminated strings in char **argv in our main function. From your question, I can see a simple path we should follow. I will assume that only one argument is expected (you should otherwise be capable of implementing cases which deal with different circumstances).
- Get the length of the first argument (
argv[1]) passed to our program.
- Populate the array with characters from the
argv[1].
- Print out our array so we know it works.
In our main function, we store the length of argv[1] to n, and declare our array of size n. We then iterate through the first string, character-by-character, and store each character into the next open slot of our array. At the end, we repeat our loop and print out each item of our array so we can verify it works.
int main (int argc, char *argv[]) {
int n = strlen(argv[1]);
char arr[n];
int i;
for (i = 0; i < n; i++)
arr[i] = argv[1][i];
for (i = 0; i < n; i++)
printf("%c ", arr[i]);
printf("\n");
}
Hope this helps. Cheers.