Solved

appending a string to the end of another

Posted on 2004-04-06
2
278 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
2 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 20 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now