i wrote a program to determine the binary digits of the entered integer. I want to implement it in other programs directly, instead of typing the same code again n again. Does anyone know? how to do that?????????

#include<conio.h>
#include<stdio.h>
int main()
{
 int n,a[20],i=0;
 printf("Enter a number: ");
 scanf("%d",&n);
  while(n!=0)
    {
     while(i<16)
      {
        a[i]= n%2;
        n=n/2;
        i++;
        break;
      }
    }
 for(i=i-1;i>=0;i--)
  {
    printf("%d",a[i]);
  }
 return 0;
}

how about making/putting functions in a header file and calling that in another program

Edited 4 Years Ago by zeroliken: added info

how about making/putting functions in a header file and calling that in another program

Hmmm... sounds good! How do we do that????? how to make our own header???

N i guess there is a way to call a program in some other program! thats why we use int main() right???

Hmmm... sounds good! How do we do that????? how to make our own header???

Have you searched the web for examples?

N i guess there is a way to call a program in some other program! thats why we use int main() right???

Now this is different than just using simple header files
Here's a link that should help you get started
http://www.gidforums.com/t-3369.html

This is where you start to learn how to write functions, use standard functions, and build related ones into libraries. Example, using your code to build on. Note that the function str2int(const char* numString) can be built into a library that you can link to any program you write, and then call from any related code.

#include <conio.h>
#include <stdio.h>
#include <ctype.h>

int str2int( const char* numString )
{
    int results = -1; // Default means not a number.
    if ((numString != NULL) || isdigit(*numString))
    {
        results = atoi(numString);
    }
    return results;
}

int main()
{
     char *buffer = 0;
     size_t numRead = 0;
     printf("Enter a number: ");
     fflush(stdout);
     buffer = getline(0, &numRead, stdin);
     if (buffer != 0)
     {
         printf("%d\n", str2int(buffer));
         free(buffer);
     }
     return 0;
}

Edited 4 Years Ago by rubberman

@zeroliken... no i didn't search for it yet!! i'll do it now.. thanks! :) and the link you've given is for LINUX do you have it for WINDOWS???

@rubberman.. these codes are going over my head.. I think i need to study basics of this first!!

Edited 4 Years Ago by Vish0203

huff... little tuff for me..!! I've just taught basics in my college, but this isa lott more than that.!!

there are following comments on that link that tells on how to do it on windows, using the Windows API, etc.

U could try invoking the exe file using command prompt... which u could initiate by using the 'system' command..

executing EXE file sounds good.........it is easiest way to run or call any program...

This article has been dead for over six months. Start a new discussion instead.