C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-08-2009, 10:42 AM   #1
Registered User
 
Join Date: Jan 2009
Posts: 37
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.
Ali.B is offline   Reply With Quote
Old 08-08-2009, 10:51 AM   #2
Registered User
 
Join Date: May 2009
Posts: 50
....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 );
}
bvkim is offline   Reply With Quote
Old 08-08-2009, 10:58 AM   #3
Registered User
 
Join Date: Jan 2009
Posts: 37
C Basic... true that.... :P i should know these stuff

but thanks bvkim... problem solved
Ali.B is offline   Reply With Quote
Reply

Tags
argument, call, function

Thread Tools
Display Modes

Forum Jump

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


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


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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