Solved

appending a string to the end of another

Posted on 2004-04-06
2
295 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:
Kent Olsen 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

856 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