Calling a function with argument

This is a discussion on Calling a function with argument within the C Programming forums, part of the General Programming Boards category; hello people... i'm having a problem with my program, its a bluetooth program that sends a message to another party ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    39

    Post Calling a function with argument

    hello people...
    i'm having a problem with my program, its a bluetooth program that sends a message to another party using the given MAC address,

    Code:
    //rfcomm Sender
    
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/socket.h>
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/rfcomm.h>
    
    int bt_send()
    {
        struct sockaddr_rc addr = { 0 };
        int s, status;
        char dest[18] = "00:03:7A:AA:92:DE"; //Another Party  MAC Address
    
        // allocate a socket
        s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
    
        // set the connection parameters (who to connect to)
        addr.rc_family = AF_BLUETOOTH;
        addr.rc_channel = (uint8_t) 1;
        str2ba( dest, &addr.rc_bdaddr );
    
        // connect to server
        status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
    
        // send a message
        if( status == 0 ) {
            status = write(s, "STOP" , 6);
        }
    
        if( status < 0 ) perror("Error ");
    
        close(s);
        return 0;
    }
    int main()
    {
    bt_send();
    }
    i need to call this function( bt_send() ) with an argument, that sits where "STOP" is now located;
    here:
    Code:
        // send a message
        if( status == 0 ) {
            status = write(s, "STOP" , 6);
        }
    how can i call this function with an argument, something like this:
    Code:
    bt_send(START);
    this would do this:
    Code:
        // send a message
        if( status == 0 ) {
            status = write(s, "START" , 6);
        }
    or this:
    Code:
    bt_send(STOP);
    that does this:
    Code:
        // send a message
        if( status == 0 ) {
            status = write(s, "STOP" , 6);
        }
    how can I do this?
    thanks in advance.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    60
    ....C basic

    Code:
    #define START "START"
    #define STOP  "STOP"
    
    int bt_send( const char *SIGNAL )
    {
    	/* .... whatever */
    	
    	// send a message
    	if( status == 0 ) {
    		status = write( s, SIGNAL, 6 );
    	}
    	
    	/* .... the rest */
    }
    
    int 
    main( void )
    {
    	bt_send( START );
    }

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    39
    C Basic... true that.... :P i should know these stuff

    but thanks bvkim... problem solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. A Function Calling a Function
    By dac in forum C++ Programming
    Replies: 8
    Last Post: 12-17-2006, 03:10 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

Tags for this Thread


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