Solved

String-handling

Posted on 2000-04-13
7
211 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
Comment Utility
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
Comment Utility
#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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Expert Comment

by:marcjb
Comment Utility
Glad to help :)
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
Community Support has reduced points from 50 to 25
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
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
Comment Utility
Thanks everybody!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now