Extract string from main () arguments

I am trying to create a pointer to one of the main () arguments in my program. I set the start pointer, then I set it to the 2nd element of the array, but I get an error when trying to compile, segmentation error. Is this because the pointer points to a bad address?

Here is the code:

char *filename;
*filename = argv[1];
printf("The filename is: %s", *filename);

I get errors regarding a pointer trying to pass an argument as an int. Is it because the pointer is actually an integer value of the address, and I'm trying to set it equal to a string?

Edit: When I go to "filename = argv [1]", I get the following error from my compiler: assignment discards qualifiers from the target pointer type.

+5
source share
4

. , , , . , , : D.

:

*filename = argv[1];

:

filename = argv[1];

? char, , . . , , , !

: filename printf(). *:).

, , * ? , ? , !

.

+7

filename , argv[1].

filename = argv[1];

(*filename = argv[1];) , , argv [1]. : a) ; b) argv[1] char*, char!

+4

*filename = argv[1]; *filename ( ) filename, .

filename = argv[1].

+3

char * , char. , (, , 0x00000000. , , : char * ( char), printf, .

:

char *filename ;
filename = argv[1] ;
printf( "The filename is: %s" , filename ) ;
0

All Articles