Question

This is the warning I get.

copyit.c: In function ‘main’:
copyit.c:15: warning: assignment makes integer from pointer without a cast
copyit.c:16: warning: assignment makes integer from pointer without a cast

The lines of code that this corresponds to are the ones that begin with pointers (*).

char source[128],target[128],buffer[512];

if(argc==3) {
*source = argv[1];
*target = argv[2];
}

I just want to assign those two things so I can pass them from the command line like that and I can then use them in my handle (ex: inhandle=open(source,O_RDONLY); Thank you.

Was it helpful?

Solution 2

Use strcpy() from string.h:

strcpy(source,argv[1]);
strcpy(target,argv[2]);

OTHER TIPS

argv is an array of string pointers. You should just change source and target to char * or const char * instead of arrays and change the code to

source = argv[3];
target = argv[4];

That will make it work. It will also prevent a buffer overflow had you copied the strings into the arrays. It would also mean your app will handle long file paths.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top