[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

appending a string to the end of another

Posted on 2004-04-06
2
Medium Priority
?
315 Views
Last Modified: 2010-04-15
how do i do this.
for instance if i have one variable: path which is "c:\" and another: command which is "windows\command\command.com" i want to append command to path to make "c:\windows\command\command.com"

how do i do this?
0
Comment
Question by:ico2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 80 total points
ID: 10765368
Hi ico2,

This is standard C....

char Buffer[100];

  strcpy (Buffer, "C:\\");                           /*  put c:\ in the buffer  */
  strcat (Buffer, "Windows\\command\\command.com");  /*  append path  */

Good Luck,
Kent
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10765380
Hi ico2,
Use strcat. Make sure your buffer is big enough.

If you're really concerned about buffer size, use snprintf:

char* path="some\\path";
char* fname="some_filename";
char fullpathbuffer[64];

snprintf(fullpathbuffer,sizeof(fullpathbuffer),"%s\\%s",path,fname);

You might need _snprintf with VC++.


Cheers,
Stefan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question