home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Pointers as parameters...HELP!

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2626
Discussions: 200,998, Posts: 2,379,963, Members: 246,365
Old September 16th, 2003, 09:17 PM   Digg it!   #1 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
Pointers as parameters...HELP!

Greetings all,

I am in the middle of testing a class I wrote to keep sorted strings together. However, I have run into a HUGE problem.

I have one function that inserts these strings into the classes array as a pointer:
Code:
void sortedStrings::insert(const char* entry)
{
 data = new char[strlen(entry)+1];
 strcpy(data,entry);
}
That is a simplified version, but it illustrates my problem.

Now the real fun begins, when entry passes into the insert function, the string is still intact (e.g. if entry = "hello", I can still print that), but after the first line where strlen() is run, if I print the value of entry I get random ASCII characters "!@@!&^as@#CV" <-- like that!

My theory is it is because strlen is trying to act on the pointer entry, and not the array of chars that entry points to, but I tried running strlen with *entry to dereference the pointer and it wouldn't compile (said couldn't convert a char to a char*...I THOUGHT IT ALREADY WAS A CHAR*!!!)

Please tell me what I am doing wrong so that strlen returns an actual length without destroying the value in entry (which you SHOULDN'T be able to change anyways since it is const!)

TIA
squeech is offline   Reply With Quote
Old September 16th, 2003, 11:45 PM     #2 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
^_^
__________________
Talking in numbers doesn't make you smarter.
squeech is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3098)
Charges against non-tippers dropped.. (22)
Health Care Rationing (17)
Foxconn Blackops x48 MoBo (5)
Nvidia GTX 260 problem (14)
Delete an OS (17)
Laptop with wireless problem. (13)
Wireless Televisions. (12)
windows vista security holes (19)
CPU fan stops spinning randomly (11)
Regular Build (11)
Point and Shoot Camera Suggestions. (9)
[F@H SPAM 11/16/09] ! 1/2 months to.. (41)
windows 7 problem (7)
Recent Discussions
Outputing 1080p from my PC to my 720p.. (0)
panasonic dmr ez48veb recorder (0)
add ram to existing (3)
Need help getting speakers to work (2)
Nvidia GTX 260 problem (14)
Laptop with wireless problem. (13)
Point and Shoot Camera Suggestions. (9)
Is the PSU I received dead? (16)
FreeAgent drive software not x64 comp.. (1)
Intel 5100 AGN issues fixed yet? (28)
Foxconn Blackops x48 MoBo (5)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (41)
Print spooler problem (17)
Q9650 vs. Q9550 (2)
Desktop Calendar Application (2)
Looking for new motherboard (1)
soundmon.exe (8)
Jedi Academy Problem (3)
Can a page file be "too big".. (1)
Size after cutting 700Mb file is 2.5 .. (0)
Delete an OS (17)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
cheap gaming laptop? (12)


All times are GMT -4. The time now is 12:28 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28