Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String-handling

Posted on 2000-04-13
7
Medium Priority
?
219 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
[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
  • 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
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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

721 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