Solved

String-handling

Posted on 2000-04-13
7
215 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 25 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
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!

 
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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 143
C++ to C# code conversion issue 4 117
Precision Problem in C++ 7 48
I could not set window to top 4 40
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

679 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