Solved

appending a string to the end of another

Posted on 2004-04-06
2
265 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

760 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

21 Experts available now in Live!

Get 1:1 Help Now