LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2003, 07:39 AM   #1
cbjhawks
Member
 
Registered: Oct 2001
Location: Overland Park, KS
Distribution: Kubuntu 22.04
Posts: 375

Rep: Reputation: 30
C++ question...


How do I append one string to another "without" using concatenate in the source code?...thanks for your reply
 
Old 11-19-2003, 09:37 AM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
rewrite the concatenate function

Code:
/*
* This doesn't do any checks, so make damn sure everything
* fits into the destination string before-hand...
*/
char *noconcat(char *dest, char *src)
{
	int len;
	char *start;
	
	len = strlen(dest);
	start = dest + len;
	strcpy(start, src);
	return dest;
}

Last edited by LogicG8; 11-19-2003 at 09:54 AM.
 
Old 11-19-2003, 09:44 AM   #3
worldmagic
Member
 
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
So whats diffrent with that code compared to the libc: strcat ? ..

$man strcat

NAME
strcat, strncat - concatenate two strings

SYNOPSIS
#include <string.h>

char *strcat(char *dest, const char *src);

DESCRIPTION
The strcat() function appends the src string to the dest string over-
writing the `\0' character at the end of dest, and then adds a termi-
nating `\0' character. The strings may not overlap, and the dest
string must have enough space for the result.
 
Old 11-19-2003, 09:53 AM   #4
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
worldmagic:
If I wrote it correctly nothing.
I didn't look at the source for glibc so
I can't give a line by line comparison.

I figured cbjhawks is stumped on a hw
question. Otherwise his question doesn't
make much sense. If he's not looking to
avoid the string library function his question
breaks down into "How do I do this without
doing it?" and while he might be looking
for overloaded operators for the String class
he's still going to have to code it someplace.
 
Old 11-19-2003, 10:21 AM   #5
worldmagic
Member
 
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
Hehe, yeaps your code should be the same as the glibc (havent checked tho).. I guess his realy thinking of the overhead of creating new String objects. Cbjhawks please clearyfy your question =) .. If you thinking of how to avoid extra allocations, strcat from libc might work, if you try to avoid some HW/SW problem using your libc implementation use the suggested code from LogicG8
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 03:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration