Passing array of characters help

This is a discussion on Passing array of characters help within the C Programming forums, part of the General Programming Boards category; GDay everyone, I have a problem that I spent so much time on it. How can I fix my code(below) ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    5

    Passing array of characters help

    GDay everyone,

    I have a problem that I spent so much time on it.

    How can I fix my code(below) to output the buffer msg_cat in function A from function B ?

    Please help if you're interested in.

    I'd appreciate it.


    Code:
    void A(){
    char *msg;
    char msg_cat[100] = "";	
    
                    //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");	
    }
    
    void B(){
                    if (strncmp(KB_buff, "display", 7) == 0){	
    		//output to screen here
                    }
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    void A()
    {
    		char *msg;
    		char msg_cat[100] = "";	
    
                    //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");	
    
        		printf("%s", msg_cat);
    		B(msg_cat);
    }
    
    void B(char * KB_buff)
    {
                    if (strncmp(KB_buff, "display", 7) == 0)
    		{	
    				//output to screen here		
    				printf("%s", KB_buff);
                    }
    }

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    		strcat(msg_cat, msg);
    		strcat(msg_cat, "\n");
    You might want to consider sprintf(), especially if you plan to add more strcat()s.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  2. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  3. passing array of structures to function
    By bvnorth in forum C Programming
    Replies: 3
    Last Post: 08-22-2003, 07:15 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. help with passing 2d array...
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-05-2002, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21