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
Solved

String-handling

Posted on 2000-04-13
7
214 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

792 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