GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Mar-2005, 06:57
weesi808 weesi808 is offline
New Member
 
Join Date: Mar 2005
Posts: 1
weesi808 is on a distinguished road

Message Producer


Hi,

I'm looking for some help, creating a message producer.

The program has many aspects to it, but specifically I am having a problem with the user inputs.

I have to get a user input, no more than 25 characters long, and store that inorder for it to be referenced and sent to a message buffer.


Below is my code if that helps:

CPP / C++ / C Code:
//Message Producer 1
//This program will create and send a message that will be displayed on screen to the user.

#include <windows.h>
#include <stdio.h>
#include <assert.h>

using namespace std;

int main(int argc, LPTSTR argv[]){
	
	char* userInput= (char*)malloc(25);

		void getUserInput(userInput) {

	printf("Please enter a message, under 25 characters, including /0 at the end");
	scanf("%s", userInput);

	int length = s.length(userInput);
}


while (length <25) {
	printf("Success. Message entererd correctly");
}
if	(length >25);
		printf("Error.  Message must be less than 25 characters.");


	
	//create a file mapping object

	HANDLE hMap = CreateFileMapping(	(HANDLE)0xffffffff, // file mapping object backed by paging file 
										0,					// default security
										PAGE_READWRITE,		// read/write access to memory 
										0,					// object size (high 32bits) 
										4096,				// object size (low  32bits)   
										"SysProgSharedMem"	// object name 
									);
	assert(hMap != 0);



	//map a view of the file to virtual memory and make 
	//it available to the process

	char* pProducerInput = (char*)MapViewOfFile(					hMap,
																	FILE_MAP_WRITE, 
																	0,				//offset high
																	0,				//offset low
																	0				// number of bytes to map = entire file 
																);
	assert(pProducerInput);


	//write some bytes to the shared memory, 
	//the other process should be able to read the bytes

	*pProducerInput = UserInput;
	*(pProducerInput+1) = '/0';



	//cleanup
	//i.e. unmap the view and close the handle

	UnmapViewOfFile(pProducerInput);
	CloseHandle(hMap);
}
Last edited by LuciWiz : 30-Mar-2005 at 07:19. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 30-Mar-2005, 09:01
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
CPP / C++ / C Code:
//...
int main(int argc, LPTSTR argv[])
{
	
	char* userInput= (char*)malloc(25);

		void getUserInput(userInput) {

	printf("Please enter a message, under 25 characters, including /0 at the end");
	scanf("%s", userInput);

	int length = s.length(userInput);
}
//...

You're nesting a function within a function, set getUserInput() outside of main() then call it as a function from within main.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Express Reply to message... NightRider Computer Software Forum - Windows 2 26-Sep-2004 02:51
Free message board hosting, 30 skins, 11 languages. edkhosting Free Web Hosting 1 27-Feb-2004 14:14
Mail message with variables ukrspp21 MySQL / PHP Forum 2 05-Aug-2003 06:10
Your message "Subject" JdS Open Discussion Forum 0 05-May-2002 03:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.