Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Drawing radio buttons - text positioning Pin
achimschoen18-Sep-06 3:37
professionalachimschoen18-Sep-06 3:37 
QuestionYahoo's sign-in seal technology Pin
George_George18-Sep-06 2:29
George_George18-Sep-06 2:29 
QuestionIOCTL Pin
Pratheep Kenny18-Sep-06 2:12
Pratheep Kenny18-Sep-06 2:12 
AnswerRe: IOCTL Pin
James R. Twine19-Sep-06 4:50
James R. Twine19-Sep-06 4:50 
QuestionSetting Color for The button control Pin
Pratheep Kenny18-Sep-06 2:08
Pratheep Kenny18-Sep-06 2:08 
AnswerRe: Setting Color for The button control Pin
Rinu_Raj18-Sep-06 2:16
Rinu_Raj18-Sep-06 2:16 
AnswerRe: Setting Color for The button control Pin
Hamid_RT18-Sep-06 2:28
Hamid_RT18-Sep-06 2:28 
QuestionClient-server program help Pin
eric_tran18-Sep-06 2:07
eric_tran18-Sep-06 2:07 
Gday everyone,

I'd like to display recent received messages in the buffer 'msg_cat' when user types in 'display', but it always displays 'No recent messages' after I concatenated messages into 'msg_cat'. I use global buffer 'msg_cat'. Is there something wrong of the way I use 'msg_cat'? Or the affect of using fork function in main?

I spent so much time on time, but I really don't know how to fix this problem.

It really depends on you guys experts here. Please help me out if you're interested in this.

I'd appreciate it.


char msg_cat[1000];	

//Receive, store and display recent messages when user type 'display'.
void displayMulticastedMessage(int condition){
	char *msg;	
	int stop = -1;	
      

        //Display recent multicast messages.
	if (condition == 2){
		if (strcmp(msg_cat, "") != 0){
			printf("msg_cat: %s", msg_cat);
			strcpy(msg_cat, "");
		}
		else{
			printf("No recent messages\n");
		}
	}

	while(stop < 0){
		//Receive multicasted messages from server and store in msg buffer.
		msg = (char *)recvfromDST (&read_EP, sockMulti);	

		//Concatenate message msg into buffer msg_cat.
		strcat(msg_cat, msg);
		strcat(msg_cat, "\n");					
	
		//Display a receiving multicast message to user
		if (msg != NULL){
			printf("----- Waiting for Multicasted message ----- \n");
			printf("\nReceived multicast message ==> %s \n", msg);
		}
		else{
			stop = 0;
		}			
	}
}



void receiveUserMessage(int sock){		
	int stop = -1;
	char *msg;	

	while (stop < 0){
		printf("Type message or 'display' to display recent multicasted messages or	'end' to quit \n");	
		
		//Read msg from user
	  		scanf ("%s", KB_buff);		
		//Display recent multicast messages.
		if (strncmp(KB_buff, "display", 7) == 0){	
			int display = 2;
			displayMulticastedMessage(display);
		}	
		
		//Check message format and send message if it is correct.
		else{			
				int stop = sentMessage(KB_buff,sock);			
		}		
		printf("\n");
	}
}



int main(){

if (pid == 0) // i am the child process
		{
			
			//Receive user input and commands
			receiveUserMessage(MC_socket);
		}
		else 
		{
			if (pid < 0) // ERROR !
			{
				perror("fork");
				exit(1);
			}
			else // parent process
			{				
				int user = -1;
				displayMulticastedMessage(user);	
						
			}
		}
}


eric

QuestionRemoving the noise from a recorded .wav file. Pin
Rajiya18-Sep-06 1:19
Rajiya18-Sep-06 1:19 
AnswerRe: Removing the noise from a recorded .wav file. Pin
Waldermort18-Sep-06 1:23
Waldermort18-Sep-06 1:23 
AnswerRe: Removing the noise from a recorded .wav file. Pin
normanS18-Sep-06 20:08
normanS18-Sep-06 20:08 
QuestionDate Operations Pin
mikobi18-Sep-06 1:06
mikobi18-Sep-06 1:06 
AnswerRe: Date Operations Pin
Naveen18-Sep-06 1:10
Naveen18-Sep-06 1:10 
GeneralRe: Date Operations Pin
Naveen18-Sep-06 1:12
Naveen18-Sep-06 1:12 
QuestionMFC /database please help ! Pin
Bravoone_200618-Sep-06 0:57
Bravoone_200618-Sep-06 0:57 
AnswerRe: MFC /database please help ! Pin
Hamid_RT18-Sep-06 1:21
Hamid_RT18-Sep-06 1:21 
GeneralRe: MFC /database please help ! Pin
Bravoone_200618-Sep-06 1:38
Bravoone_200618-Sep-06 1:38 
GeneralRe: MFC /database please help ! Pin
Hamid_RT18-Sep-06 1:58
Hamid_RT18-Sep-06 1:58 
QuestionRe: MFC /database please help ! Pin
David Crow18-Sep-06 5:12
David Crow18-Sep-06 5:12 
QuestionCan not start program with DataGrid Pin
NorGUI18-Sep-06 0:49
NorGUI18-Sep-06 0:49 
QuestionHelp me Pin
sonyama18-Sep-06 0:48
sonyama18-Sep-06 0:48 
AnswerRe: Help me Pin
_AnsHUMAN_ 18-Sep-06 0:51
_AnsHUMAN_ 18-Sep-06 0:51 
GeneralRe: Help me Pin
sonyama18-Sep-06 0:54
sonyama18-Sep-06 0:54 
GeneralRe: Help me Pin
_AnsHUMAN_ 18-Sep-06 0:58
_AnsHUMAN_ 18-Sep-06 0:58 
GeneralRe: Help me Pin
sonyama18-Sep-06 1:02
sonyama18-Sep-06 1:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.