I am facing some problem in my final year project

Project Steps:

1. The PC should scan the any blue tooth from Mobile(More then one mobile may be)
2. It should register the Blue tooth
3. Automatically when Blue tooth is dectected from my mobile it should go Silent mode

SO far i have done this much:

For scanning blue tooth devices
Code:
#include<stdio.h>
#include<fcntl.h>
int main()
 {

   int fd;
   char buff[20],buf[50];

   system(" rm abc.txt");
   system("hcitool scan >> abc.txt");

   fd=open("abc.txt",O_RDONLY);
   lseek(fd,12,SEEK_SET);
   read(fd,buff,19);

   puts(buff);
  
   sprintf(buf,"rfcomm release /dev/rfcomm0 %s %d",buff,2);
   puts(buf);
   system(buf);
   
   sprintf(buf,"rfcomm bind /dev/rfcomm0 %s %d",buff,2);
   puts(buf);

   system(buf);
  
 }
For Turning automatically silent mode for Mobile

Code:
#include<stdio.h>
#include<stdlib.h>



int main()
 {


  FILE *fp;


  fp=fopen("/dev/rfcomm0","w");


  if (fp==0)
    printf(" Problem...");

  system("cat /dev/rfcomm0 &");

  printf("\n CAT..");

  system(" echo at+csil=0 > /dev/rfcomm0");

  exit(0);


 }
Now i am facing problems with this code is:-
1. It will work only for one blue tooth device
2. It is not registering scanned blue tooth device
3. how can i combine these two peace of code into single

Could any body help me to solve this ? i have demo tomorrow
Regards.
Shidlingayya