char *env


I am having a problem with char *env and storing filename into char bufferFileName.

Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
int main(int argc, char** argv, char *env [])
{
//user inputs: 1234 127.0.0.1 file.txt
char fileNameBuff[100];
strncpy(fileNameBuff, argv[3], strlen(argv[3]));
	{
		size_t i;
		for (i=0; i<strlen(argv[3]) && argv[3] !='\0';i++)
		fileNameBuff[i] = argv[i];

	
	}
}

strncpy(fileNameBuff, argv[3], 100);
why 100?
Because that is the size of the buffer char fileNameBuff[100];
strncpy() is safe, it won't overflow beyond the destination size, but that size needs to be supplied in the function call.
thank you! so I dont even need a loop. just strncpy(fileNameBuff, argv[3], 100);
thanks again.
Topic archived. No new replies allowed.