Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2006, 9:43 PM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
*operater and arrays

Ok the following code is being used to store an array of strings (being stored with memcpy). What is the * operater doing in the array declaration? I can't figure it out for the live of me! Is it just being used to declare 6000 elements?
char G_cMsgList[120*50];



this is the routine used to store the Msg! I understand common things but certain thing like "cTemp + 120" is beyond me! Why would memcpy be used to store the msg's array (G_cMsgList) in cTemp them use memcpy again to store the new msg in cTemp and then take cTemp and put it in G_cMsgList again!
void PutLogList(char * cMsg)
{
 char cTemp[120*50];
	
	G_cMsgUpdated = TRUE;
	ZeroMemory(cTemp, sizeof(cTemp));
	memcpy((cTemp + 120), G_cMsgList, 120*49);
	memcpy(cTemp, cMsg, strlen(cMsg));
	memcpy(G_cMsgList, cTemp, 120*50);

}


This is used to output the msg's (WM_PAINT). The main thing i don't understand is why the the declaration for a string is char * cMsg;.
void OnPaint()
{
 HDC hdc;
 PAINTSTRUCT ps;
 register short i;
 char * cMsg;

	hdc = BeginPaint(G_hWnd, &ps);

	SetBkMode(hdc,TRANSPARENT);

	for (i = 0; i < 35; i++) {
		cMsg = (char *)(G_cMsgList + i*120);
		TextOut(hdc, 5, 5 + 600 - i*16, cMsg, strlen(cMsg));
	}

            	EndPaint(G_hWnd, &ps);




The reason for all of this is because im writting a text based rpg (still) using Win32 and I want to paint text (ofcourse). 1 first msg (line) being at the bottom of the window and each time i want to output a new msg (line) it is placed at the bottom and everything else shifts up a line. The code you see performs this action.. but i would never rip it. I want to completely understand how it was done before i attempt it (re-written). Thanks
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Jun 22nd, 2006, 10:05 PM   #2
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
>Is it just being used to declare 6000 elements?

Yes.

And char * cMsg; is just a pointer to the text contained in the G_cMsgList array.

[EDIT]

memcpy((cTemp + 120), G_cMsgList, 120*49);
memcpy(cTemp, cMsg, strlen(cMsg));
memcpy(G_cMsgList, cTemp, 120*50);
Copies the first 5880 elements in G_cMsgList into the cTemp array - starting from cTemp[120]. Then it copies the cMsg (current message?) into the start of cTemp. Now cTemp contains the new message, followed by the original first 49 entries in G_cMsgList. Then we copy that data back into the G_cMsgList array. So, basically, it just shifts the oldest message out and the newest message into the beginning of the array.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...

Last edited by bivhitscar; Jun 22nd, 2006 at 10:19 PM.
bivhitscar is offline   Reply With Quote
Old Jun 22nd, 2006, 10:09 PM   #3
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
but why char * cMsg why not char* cMsg or char *cMsg??? Or are they all the same?
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Jun 22nd, 2006, 10:16 PM   #4
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Yes, they are all the same.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Jun 23rd, 2006, 8:19 AM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Btw it's written 'operator' not 'operater'.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jun 23rd, 2006, 10:18 AM   #6
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
thanks nnxion i wrote these post last night after drinking a 6-pack. Anyone else have any insight about all of my other questions?
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Jun 23rd, 2006, 10:32 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It isn't a matter of insight. Which question did you ask that you didn't see an answer for?
Quote:
What is the * operater doing in the array declaration?
It's probably to remind the coder that the total number of elements declared represents a partitioning of m x n.
	memcpy((cTemp + 120), G_cMsgList, 120*49);
	memcpy(cTemp, cMsg, strlen(cMsg));
	memcpy(G_cMsgList, cTemp, 120*50);
The first statement moves the message list into the temp area 120 bytes down from the beginning. The second statement moves cMessage to the beginning of the temp area (before the old message list). The third statement replaces the old message list with the new arrangement. This puts new messages at the front of the list, not at the rear. Capish?
Quote:
i don't understand is why the the declaration for a string is char * cMsg;.
As mentioned above, char *thangy, char* thangy, and char * thangy are equivalent.

Okay?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 23rd, 2006, 12:06 PM   #8
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 259
Rep Power: 3 Cache is on a distinguished road
Perhaps part of the question is why use memcpy when C++ provide several abstractions for such operations. My anwser would be: I wouldn't. The code posted is probably written in C.
Cache is offline   Reply With Quote
Old Jun 24th, 2006, 3:57 AM   #9
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
>Anyone else have any insight about all of my other questions?

I hate repeating DaWei, but what did you ask that I didn't answer?
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Old Jun 24th, 2006, 10:32 PM   #10
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
I guess they were anwsered! lol sorry I had more then i didn't write... so i should be able to perform the same output using a (string) vector correct?
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC