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;
}
}