converting char to char *

All,

I am trying to take an array of arguments from char **argv and combine them in one string.

I keep receiving the following error: error C2664: 'strcat' : cannot convert parameter 1 from 'char' to 'char *'
Attached is the code I am using.

Anyone know of a way I can accomplish the above?

Thanks
int main(int argc, char **argv) 
{
	char *sendbuf = "";
	for(int i = 1; i < argc; i++) 
	{
		if((i > 3) && (i < argc))
		{
			strcat(*sendbuf, argv[i]); //Line with error
		}
		printf("Argument: %s\n", argv[i]);
	}
}

Open in new window

tr57285Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
sendbuf is a char*
*sendbuf is a char ('\0' in this case)

You cannot strcat to a string literal anyway.

What you should do, is allocate enough memory to hold all command line arguments, and then you can strcat them together :

int main(int argc, char **argv) 
{
        char sendbuf[1024] = "";
        for(int i = 1; i < argc; i++) 
        {
                if((i > 3) && (i < argc))
                {
                        strcat(sendbuf, argv[i]);
                }
                printf("Argument: %s\n", argv[i]);
        }
        return 0;
}

Open in new window

0
jkrCommented:
>>I am trying to take an array of arguments from char **argv and combine
>>them in one string.

Since you are apparently on Windows: Just call 'GetCommandLine()' (http://msdn.microsoft.com/en-us/library/ms885605.aspx) to get the full command line as one string. E.g.
#include <windows.h>
 
int main(int argc, char **argv) 
{
        char *sendbuf = GetCommandLine();
 
  return 0;
}

Open in new window

0
tr57285Author Commented:
jkr,

Thanks, but now I am receiving the following error:

error C2440: 'initializing' : cannot convert from 'LPWSTR' to 'char *
0
jkrCommented:
Ah, you have UNICODE set - in this case, use
#include <windows.h>
 
int main(int argc, char **argv) 
{
        char *sendbuf = GetCommandLineA(); // explicitly call ANSI version
 
  return 0;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tr57285Author Commented:
Thanks jkr, That fixed it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.