Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copying a string
06-03-2010, 05:31 AM
Post: #11
RE: copying a string
(06-03-2010 04:28 AM)BlueMelon Wrote:  Well, it adds every line over and over again because of the

Code:
for (int i=0; i<social_sites; i++)

So... Even if i do the NULL to the string after it's been added, it's still going to do that? No work around for it? Is there an example i can look at when doing an array and pulling data from it to strncat to a string that i can clear it and start from the top, down again? Please let me know. Thank you.

Regards,
./x86
Find all posts by this user
Quote this message in a reply
01-06-2011, 02:56 PM (This post was last modified: 01-06-2011 02:59 PM by Xupicor.)
Post: #12
RE: copying a string
Why would you even need strncpy() or strcat() if you could be working with std::string?

Code:
using std::string;
//...
string hello = "Hi there!"; // string literal is copied into new string object
string hi = hello; // done, hi is now a copy of hello
string howdy(hello); // done, just a different syntax

string line;
std::getline(std::cin, line); // takes input from a user, the whole line of text that is (by default until '\n' character).
std::cout << line << "\n"; // see for yourself

Oh, and instead of using plain array, why not use a std::vector<std::string> (a vector of strings)?
Find all posts by this user
Quote this message in a reply
01-07-2011, 03:44 AM
Post: #13
RE: copying a string
It depends if you are using C or C++. In C++ std::string or even string library <string> can be used.
But in C you need either to write functions from scratch or to use <cstring> library or any other.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
01-07-2011, 04:11 AM
Post: #14
RE: copying a string
True, but since the OP used string in original paste, I thought it is about C++. Yet another point why separating C and C++ forums would clear some things up. Wink
Also, you should be aware that <string> is a header file that std::string is defined in. Wink
Find all posts by this user
Quote this message in a reply
01-07-2011, 04:18 AM
Post: #15
RE: copying a string
Yeah definitely, std::string is defined in <string>.
And C/C++ forum is the most popular, and Pascal and Delphi don't have as much threads together as C/C++.
We are going to discuss that definitely.

That happened because in the beginning most users of this forum were Pascal/Delphi programmers and we
wanted to separate that, to have a clear line between those two languages.
Not much users were using C or C++, so we had a general "C-based languages" forum which was splitted
when it had grown.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: