Convert char* to char[] ?
I know this should be easy but I can't figure it out, how can I convert a char* to a char[] array? I'm not using CLR or MFC.
Here's what I have so far, using main ( int argc, char* argv[] )
char inchar[33];
char tempchar = 'a'; /* dummy value to start */
int count = 0;
while ( tempchar != '\0' )
{
tempchar = argv[1][count];
inchar[count] = tempchar;
count = count + 1;
}
fprintf(stdout, inchar);
When I run it like PROG.EXE DOG
I get only D as the output ( the first character only every time ).
Re: Convert char* to char[] ?
I compiled and ran your code with no problems, it printed "Dog".
There is actually no real difference between an array of char or a pointer to char, so no conversion should be necessary.
Have you debugged the application and stepped through the loop to see if you can gather any clues as to why its behaving like that?
Re: Convert char* to char[] ?
Weird. Its Visual Studio 2008, a console application ( not CLR or MFC ), this is the exact code, I put the print out of the argument right below the main:
int _tmain(int argc, char* argv[])
{
fprintf(stdout, argv[1]);
...
Typing PROG.EXE DOG still shows just D
Re: Convert char* to char[] ?
Oh Got it. When I created the Application it was something like this:
int _tmain(int argc, _TCHAR* argv)
Changing it to the old way worked ( I had to change the function name too from _tmain to main )
int main(int argc, char* argv[])