Click here to Skip to main content
14,773,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i convert from char to char[] i can pass char[] value only to my function but the value i am retrieving is in char

What I have tried:

while (cDriveLetter <= 'Z')
	{
		if (0 < (dwDrivemap & 0x00000001L))
		{
		  cDriveLetter;
		/*  char *p;
		  p = new char[1];
		  p= cDriveLetter;*/
		   char arr[] = cDriveLetter;
		  if (getfil((void*)arr) == 0)
		  {
			  getfil((void*)arr);
		  }
			//printf("%c:\\\n", cDriveLetter);
			//return cDriveLetter;
		  else
			  cDriveLetter++;
		}
		cDriveLetter++;
		dwDrivemap = dwDrivemap >> 1;
	}
Posted
Updated 17-Feb-20 9:05am
Comments
CPallini 18-Feb-20 3:45am
   
Please show the getfil function implementation.

1 solution

Try:
char arr[] = &cDriveletter;
Or
char arr[2];
arr[0] = cDriveLetter;
arr[1] = '\0';
And then pass arr to your function.
The latter is safer as it allocates the space for the char and a trailing null to terminate a "C-style" string. The former will work if getfil only uses the first character of the array passed to it.
   
Comments
Stefan_Lang 18-Feb-20 2:28am
   
Since getfil() uses its argument to initialise a string, you need a 0-terminated C string as input. Use OriginalGriff's second suggestion and that part of your code should work fine.

If there is any other issue than this, you should explain that more clearly. Moreover, this kind of unformatted codedump is a pain to read. If you need further help, I strongly suggest you update your original question using the [Improve Question] button at the lower right of your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900