?
Solved

appending a string to the end of another

Posted on 2004-04-06
2
Medium Priority
?
311 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

Independent Software Vendors: 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

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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

764 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