We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,294 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to call a program in another program?

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;
}
6
Contributors
10
Replies
3 Weeks
Discussion Span
11 Months Ago
Last Updated
11
Views
Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

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???

Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

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;
}
rubberman
Posting Maven
2,578 posts since Mar 2010
Reputation Points: 365
Solved Threads: 307
Skill Endorsements: 52

@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!!

Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

Vish0203
Junior Poster
144 posts since Apr 2012
Reputation Points: -6
Solved Threads: 9
Skill Endorsements: 0

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

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

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

adityatandon
Junior Poster
114 posts since Dec 2011
Reputation Points: 33
Solved Threads: 13
Skill Endorsements: 0
Sokurenko
Junior Poster
111 posts since May 2012
Reputation Points: 42
Solved Threads: 13
Skill Endorsements: 0

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

Sky_Flyer
Newbie Poster
2 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0983 seconds using 2.74MB