Я поиграюсь с некоторыми указателями c прямо сейчас, но у меня проблема в том, что какой-то указатель из массива, взятого аргументами, выводит неверно на втором аргументе, или даже указывает на неправильный адрес. Что здесь за дело?
Argument 1 is named : test and has the address of : 0x7ffe563f45e3
Argument 2 is named : test123 and has the address of : 0x7ffe563f45e8
Argument 3 is named : hmm and has the address of : 0x7ffe563f45f0
Argument 4 is named : weird and has the address of : 0x7ffe563f45f4
ArgumentPointer 1 is named : test and has the address of : 0x7ffe563f45e3
ArgumentPointer 2 is named :��y�U and has the address of : 0x7ffe563f3c08
ArgumentPointer 3 is named : hmm and has the address of : 0x7ffe563f45f0
ArgumentPointer 4 is named : weird and has the address of : 0x7ffe563f45f4
Вот код:
#include <stdio.h>
int main(int argc, char*argv[])
{
char *arguments[] = { "" };
if (argc == 1)
{
printf("There are no Arguments given!\n\n");
}
for (int i = 1; i < argc; i++)
{
arguments[i] = argv[i];
printf("Argument %d is named : %s and has the address of : %p\n",i
, arguments[i],
arguments[i]);
}
printf("\n");
char **argumentPointer = arguments;
for (int i = 1; i < argc; i++)
{
printf("ArgumentPointer %d is named : %s and has the address of :
%p\n", i, argumentPointer[i],
argumentPointer[i]);
}
}