Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Please help solve a programming problem.
Please help solve a programming problem.
Yes, it has been debugged. I don't know if it's the function you requested. Give it a try:

# include & ltstdio.h & gt

# include & ltstring.h & gt

# Define the maximum quantity of 20

Typedef structure {

char str 1[MAX _ NUMBER];

char str 2[MAX _ NUMBER];

int pos 1;

int pos2

} crossStruct

cross struct cs[2];

int MakeCross(crossStruct *cs)

{

int i,j;

cs-& gt; pos 1 = 0;

cs-& gt; pos 2 = 0;

for(I = 0; I< (int) strlen (cs->; str 1); i++)

for(j = 0; j & lt(int)strlen(cs-& gt; str 2); j++)

if(cs-& gt; str 1[I]= = cs-& gt; str2[j])

{

cs-& gt; pos 1 = j;

cs-& gt; pos 2 = I;

Returns1;

}

Returns 0;

}

void ShowCross()

{

int i,j,len 1 1,len 12,len2 1,len22

len 1 1 = strlen(cs[0]. str 1);

len 12 = strlen(cs[0]. str 2);

len 2 1 = strlen(cs[ 1]. str 1);

len 22 = strlen(cs[ 1]. str 2);

int height = len 12 & gt; len22? len 12:len 22;

int width = len 1 1+len 2 1+3;

for(I = 0; I am < height; i++)

{

for(j = 0; J< width; j++)

{

if(I = = cs[0]. pos 1 & amp; & ampj & ltlen 1 1)printf("%c ",cs[0]. str 1[j]);

else if(I & lt; len 12 & amp; & ampj==cs[0].pos2)printf("%c ",cs[0]. str 2[I]);

else if(I = = cs[ 1]. pos 1 & amp; & ampj & gt=len 1 1+3。 & ampj & lt width)

printf("%c ",cs[ 1]. str 1[j-3-len 1 1]);

else if(I & lt; len22 & amp& ampj = = cs[ 1]. pos 2+len 1 1+3)printf(" % c ",cs[ 1]. str 2[I]);

else printf(" ");

}

printf(" \ n ");

}

}

void ShowCrossToFile(FILE *fp)

{

int i,j,len 1 1,len 12,len2 1,len22

len 1 1 = strlen(cs[0]. str 1);

len 12 = strlen(cs[0]. str 2);

len 2 1 = strlen(cs[ 1]. str 1);

len 22 = strlen(cs[ 1]. str 2);

int height = len 12 & gt; len22? len 12:len 22;

int width = len 1 1+len 2 1+3;

for(I = 0; I am < height; i++)

{

for(j = 0; J< width; j++)

{

if(I = = cs[0]. pos 1 & amp; & ampj & ltlen 1 1)fprintf(fp," %c ",cs[0]. str 1[j]);

else if(I & lt; len 12 & amp; & ampj==cs[0].pos2)fprintf(fp," %c ",cs[0]. str 2[I]);

else if(I = = cs[ 1]. pos 1 & amp; & ampj & gt=len 1 1+3。 & ampj & lt width)

fprintf(fp," %c ",cs[ 1]. str 1[j-3-len 1 1]);

else if(I & lt; len22 & amp& ampj = = cs[ 1]. pos 2+len 1 1+3)fprintf(FP," %c ",cs[ 1]. str 2[I]);

else fprintf(fp," ");

}

fprintf(fp," \ n ");

}

}

void main(int argc,char *argv[])

{

if(argc== 1)

{

Printf ("Please enter 4 strings:");

scanf("%s %s %s %s ",cs[0].str 1,cs[0].str2,cs[ 1].str 1,cs[ 1]. str 2);

if(make cross(& amp; cs[0])& amp; & ampmake cross(& amp; cs[ 1]))show cross();

Else printf ("can't make two crosses. \ n ");

}

other

{

char ipname[255],op name[255];

int result = 1;

FILE *ifp,* ofp

strcpy(ipname,argv[ 1]);

if(argc==2)

{

Printf ("Please enter the target file name:");

scanf("%s ",op name);

}

else strcpy(opname,argv[2]);

ifp=fopen(ipname," r ");

If (! ifp)

{

Printf ("Error opening file% s." ,IP name);

Return;

}

ofp=fopen(opname," w ");

If (! ofp)

{

Printf ("Error creating file% s." ,op name);

Return;

}

And (! Association of foreign investors. & result)

{

fscanf(ifp," %s %s %s %s ",cs[0].str 1,cs[0].str2,cs[ 1].str 1,cs[ 1]. str 2);

fprintf(ofp," %s %s %s %s\n ",cs[0].str 1,cs[0].str2,cs[ 1].str 1,cs[ 1]. str 2);

if(cs[ 1]. str R2[strlen(cs[ 1]. str 2)- 1]= = ' # ')

{

cs[ 1]. str 2[strlen(cs[ 1]. str 2)- 1]= 0;

Result = 0;

}

if(make cross(& amp; cs[0])& amp; & ampmake cross(& amp; cs[ 1]))ShowCrossToFile(ofp);

Else fprintf(ofp, "cannot cross twice. \ n ");

fprintf(ofp," ~-~ ");

}

fclose(ifp);

fclose(ofp);

}

}