combineing two programs

This is a discussion on combineing two programs within the C++ Programming forums, part of the General Programming Boards category; I have these two programs and I want to combine them into one program. I think I need a if ...

  1. #1
    Unregistered
    Guest

    combineing two programs

    I have these two programs and I want to combine them into one program. I think I need a if then else statement any Ideas?

    #include <stdio.h>
    main (argc,argv)
    int argc;
    char *argv[];
    {
    FILE *fp, *fopen();
    filecopy(stdin);
    }
    filecopy(fp)
    FILE *fp;
    {
    int c;
    const int n=19;
    int ptr=0;
    int match=0;
    int prefill=0;
    int index=0;
    int arraysizeC=7;
    int A[19];
    int B[19];
    int C[7];
    int D[19];

    B[0]='h';
    B[1]='t';
    B[2]='t';
    B[3]='p';
    B[4]=':';
    B[5]='/';
    B[6]='/';
    B[7]='r';
    B[8]='t';
    B[9]='p';
    B[10]='m';
    B[11]='e';
    B[12]='t';
    B[13]='l';
    B[14]='i';
    B[15]='f';
    B[16]='e';
    B[17]='3';
    B[18]='/';

    C[0]='h';
    C[1]='t';
    C[2]='t';
    C[3]='p';
    C[4]='s';
    C[5]=':';
    C[6]='/';

    D[0]='/';
    D[1]='m';
    D[2]='l';
    D[3]='0';
    D[4]='2';
    D[5]='.';
    D[6]='a';
    D[7]='c';
    D[8]='s';
    D[9]='s';
    D[10]='.';
    D[11]='a';
    D[12]='t';
    D[13]='t';
    D[14]='.';
    D[15]='c';
    D[16]='o';
    D[17]='m';
    D[18]='/';

    while ((c=getc(fp)) != EOF)
    {
    /* Loading Array A[] */
    if (prefill==0)
    {
    A[ptr]=c;
    ptr++;
    if(ptr==n)
    {
    ptr=0;
    prefill=1;
    }
    }
    else
    {
    /* Match Array A[] with Array B[] */
    putc (A[ptr],stdout);
    A[ptr]=c;
    if(match != 0)
    {

    if (c==B[match])
    {
    match++;
    if(match==n)
    {
    for (match=0; match <arraysizeC; match++)
    {
    putc (C[match],stdout);
    }
    for (match=0; match <n; match++)
    {
    ptr++;
    if(ptr==n)ptr=0;
    A[ptr]=D[match];
    }
    match=0;
    }
    }
    else match=0;

    }
    else if (c == 'h')match=1;

    ptr++;
    if (ptr==n)ptr=0;
    }
    }

    for (prefill=0;prefill<n;prefill++)
    {
    putc(A[ptr],stdout);
    ptr++;
    if (ptr==n)ptr=0;
    }
    }


    NEXT PROGRAM

    #include <stdio.h>
    main (argc,argv)
    int argc;
    char *argv[];
    {
    FILE *fp, *fopen();
    filecopy(stdin);
    }
    filecopy(fp)
    FILE *fp;
    {
    int c;
    const int n=19;
    int ptr=0;
    int match=0;
    int prefill=0;
    int index=0;
    int arraysizeC=7;
    int A[19];
    int B[19];
    int C[7];
    int D[19];

    B[0]='h';
    B[1]='t';
    B[2]='t';
    B[3]='p';
    B[4]=':';
    B[5]='/';
    B[6]='/';
    B[7]='r';
    B[8]='t';
    B[9]='p';
    B[10]='m';
    B[11]='e';
    B[12]='t';
    B[13]='l';
    B[14]='i';
    B[15]='f';
    B[16]='e';
    B[17]='2';
    B[18]='/';

    C[0]='h';
    C[1]='t';
    C[2]='t';
    C[3]='p';
    C[4]='s';
    C[5]=':';
    C[6]='/';

    D[0]='/';
    D[1]='m';
    D[2]='l';
    D[3]='0';
    D[4]='1';
    D[5]='.';
    D[6]='a';
    D[7]='c';
    D[8]='s';
    D[9]='s';
    D[10]='.';
    D[11]='a';
    D[12]='t';
    D[13]='t';
    D[14]='.';
    D[15]='c';
    D[16]='o';
    D[17]='m';
    D[18]='/';

    while ((c=getc(fp)) != EOF)
    {
    /* Loading Array A[] */
    if (prefill==0)
    {
    A[ptr]=c;
    ptr++;
    if(ptr==n)
    {
    ptr=0;
    prefill=1;
    }
    }
    else
    {
    /* Match Array A[] with Array B[] */
    putc (A[ptr],stdout);
    A[ptr]=c;
    if(match != 0)
    {

    if (c==B[match])
    {
    match++;
    if(match==n)
    {
    for (match=0; match <arraysizeC; match++)
    {
    putc (C[match],stdout);
    }
    for (match=0; match <n; match++)
    {
    ptr++;
    if(ptr==n)ptr=0;
    A[ptr]=D[match];
    }
    match=0;
    }
    }
    else match=0;

    }
    else if (c == 'h')match=1;

    ptr++;
    if (ptr==n)ptr=0;
    }
    }

    for (prefill=0;prefill<n;prefill++)
    {
    putc(A[ptr],stdout);
    ptr++;
    if (ptr==n)ptr=0;
    }
    }

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    39
    Do you mean put the source code of one program into another or put 2 source codes into one program? If that's what you mean just do something like the follwing.
    Code:
    #include "file.cpp"
    #include "file2.cpp"
    Put this code where you want it to be.
    Compiler: Dev-C++ 4.9.8.0

    -Bert

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Aside from not using "code" tags - if I hadn't mentioned it, someone else would have - neither of your "programs" will even compile.

    First, and foremost, you attempt to define main() with no return type. It's a function afterall.

    Second, 'argc' and 'argv' are declared after you assign them as parameters to main(). Won't fly. Not with C++, anyway. (At the very least, they should be declared within the function braces.) That is:
    Code:
    int main(int argc, char* argv[])
    (Prelude is great with this stuff...I'm not.)

    Bottom line, even without the code being refined, I think you're in need of more than an IF...THEN...ELSE statement here.

    Compile your code first, find the errors in it and, if you can't resolve them, come to the Board. With all due respect, at this point, you're asking a lot, from my perspective, anyway.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well just including it wont solve the problem.. because if u iclude bboth the prog like that.. The variable names etc ect main function conflict... SO the prog wont compile...

    First compile these two prog and create an exe.. and make another prog with an option and call the required program by using system("requiredprogram.exe");

    So in a way this will solve your problem.. But there can be no communication between the two programs.. if u really want to add the two.. then u will have to do a lot od recoding...

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: combineing two programs

    Originally posted by Unregistered
    Code:
    main (argc,argv)
    int argc;
    char *argv[];
    {
    	FILE *fp, *fopen();
    	filecopy(stdin);
    }
    I think this is an old style of a function definition. Switch to the ANSI C style like skipper told you.
    What compiler do you use?

  6. #6
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Heh... haven't seen code like that for some time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  2. Newbie question: pointers, other program's memory
    By xxxxme in forum C++ Programming
    Replies: 23
    Last Post: 11-25-2006, 12:00 PM
  3. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM
  4. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM
  5. Programs Communicating
    By Drek in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2002, 03:47 PM

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