Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

String-handling

Posted on 2000-04-13
7
Medium Priority
?
221 Views
Last Modified: 2010-04-02
Hi!

How do I do this:

char str[] = "DSN=MYDSN\0" "DBQ=test.mbd";
If I have MYDSN and test.mbd in variables?
I can't do strcpy & strcat, because the string will be truncated at the null-character. If I don't have the \0 , the DBQ will not be added when I then use this str as the last parameter in SQLConfigDataSource()

Thanks!

 
0
Comment
Question by:Scattan
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 1

Expert Comment

by:mahno
ID: 2711679
Hi,

try this way:

char str[256];
char *var1 = "MYDSN";
char *var2 = "test.mbd";
int len;

strcpy(str, "DSN=");
strcat(str, var1); //
 
len = strlen(str); //save index
strcat(str, "\xff"); //insert temp character

strcat(str, "DBQ=");
strcat(str, var2);
str[len] = 0; // replace temp character with '\0'

Hope this helps,
  mahno
0
 
LVL 3

Accepted Solution

by:
marcjb earned 100 total points
ID: 2711719
#include <stdio.h>
#include <string.h>

int main()
{
char str[256];
char var1[] = "DSN=MYDSN";
char var2[] = "DBQ=test.mbd";
strcpy(str, var1);
memcpy(str + strlen(str) + 1, var2, strlen(var2) + 1);
}

/* The plus 1's grab the NULL's */
0
 

Author Comment

by:Scattan
ID: 2711895
Hi mahno & marcjb!

Thanks for your answers.
They both worked very well, so I will asking community support to split the points between you two.
Thanks!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:marcjb
ID: 2712034
Glad to help :)
0
 
LVL 3

Expert Comment

by:darinw
ID: 2713195
Community Support has reduced points from 50 to 25
0
 
LVL 3

Expert Comment

by:darinw
ID: 2713196
Hello all,

I am reducing the points on this question to allow the split.

Scattan, you can accept one of the Experts comments as an answer to award the first half of the points. Remember, the Accept Comment as Answer button is in the comment header.

For the second Expert, please create a new question in this topic area. The new question title should be 'For ExpertName -- 10327719' with 25 points.

For your convenience, you can use this link to create the new question:

http://www1.experts-exchange.com/bin/NewQForm?ta=30

darinw
Customer Service
0
 

Author Comment

by:Scattan
ID: 2714963
Thanks everybody!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

877 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