Home > Back-end >  River's lake emergency! C language homework tomorrow, the first modify the program to display m
River's lake emergency! C language homework tomorrow, the first modify the program to display m

Time:09-27

Big trouble to help me see where is wrong, can always output of the first word of the first program wubi input code, a second program cannot output,
The first program:
//GetWb. CPP: Defines the entry point for the console application. 
//
#include
#include
#include

Char GCD (char [], int num);

Int main (int arg c, char * argv [])
{

Int I=1;
If (argc<2) {
Printf (" \ Error input!" );
exit(1);
}
While (iThe GCD (argv [I], I);
I++;;
}
return 0;
}

Char GCD (char [], int num)
{
Unsigned char ch1 and ch2.
FILE *fp;
int m,n;
Ch1=* a - 0 xa0;
Ch2=* (a + 1) - 0 xa0;
Printf (" ch1=% d, ch2=% d ", ch1 and ch2);

N=(ch1-16) * 94 + ch2-1;
Fp=fopen (WB. IMD ""," rb ");
If (fp==NULL) {
Printf (" Error "open file wb. Imd");
exit(1);
}
Fseek (fp, 128 + n * 4, 0).
For (m=0; m<=3; M++) {
Printf (" % c ", fgetc (fp));
}
}

A second program:
//p2. CPP: Defines the entry point for the console application. 
#include
#include

# # ifndef _ARRAY_H_
# define _ARRAY_H_

# define LEN 100

Typedef struct {
Char * array;
int size;
} Array;

Array fnInput (char [x]);
Array fnAdd (Array * a, * b Array, Array * c);
Array fnSub (Array * a, * b Array, Array * c);
Array fnPrint (Array * a);

Array [LEN + 1], a [b LEN + 1], c [LEN + 1];

Array array_create (int init_size);
Void array_free (Array * a);
Char * array_at (Array * a, int index);
Void array_inflate (Array * a, int more_size);

Array array_create (int init_size)//create an Array
{
Array a;//a is a local variable
A.a rray=(char *) malloc (sizeof (init_size (int *)));
A.s considering=init_size;
return a;
}

Void array_free (a) Array *//release
{
Free (a - & gt; Array);
A - & gt; Array=NULL;
A - & gt; Size=0;
}

Char * array_at (Array * a, int index)//returning a pointer to a char, convenient for it in another function assignment, such as * array_at (& amp; A, 0)=1;
{
Return & amp; (a - & gt; Array [index]);
}

Void array_inflate (Array * a, int more_size) grew up//
{
Char * p=(char *) malloc (sizeof ((int) (a - & gt; The size + more_size)));//get a new space
int i;
If (p==NULL) {
Printf (" No enough memory!" );
exit(0);
}
The else {
for(i=0; i{
P=a - [I] & gt; Array [I];
}//copies of the original to the new space to
Free (a - & gt; Array);
A - & gt; Array=p;
A - & gt; The size +=more_size;
}
}

Int main (void)
{
Printf (" both Please input a number: ");
FnInput (a - & gt; Array);

Printf (" both Please input another number: ");
FnInput (b - & gt; Array);


FnAdd (a, b, c);
printf("\n");
FnPrint (a);
Printf (" + ");
FnPrint (b);
Printf ("=");
FnPrint (c);

FnSub (a, b, c);
printf("\n");
FnPrint (a);
Printf (" - ");
FnPrint (b);
Printf ("=");
FnPrint (c);

Array_free (a);
Array_free (b);
Array_free (c);
return 0;
}

Array fnInput (char [x])
{
Array b;
B=array_create (100);
Int z;
for(z=0; getchar()!='\ n') {
The scanf (" % c ", array_at (& amp; B, z));
Z++;
}
}

Array fnAdd (Array * a, * b Array, Array * c)
{
int m,n;
M=a - & gt; size;
N=b - & gt; size;
int i;
Char r;
While (i>=0)
{
If (m>=n) {
R=m + 1;
}
The else {
R=n + 1;
}
R=a - & gt; Array [m] + b - & gt; Array [n].
If (r> 9)
{
C - & gt; Array [I + 1)=c - & gt; Array [I + 1) + r % 10;
If (c - & gt; Array [I + 1] <10) {
i--;
M -;
N -;
C - & gt; Array [I + 1)=1;
}
Else if (c - & gt; Array [I + 1] & gt;=10) {
C - & gt; Array [I + 1)=0;
i--;
M -;
N -;
C - & gt; Array [I + 1)=1;
}
}
The else {
C - & gt; Array [I + 1)=c - & gt; Array [I + 1) + r;
i--;
M -;
N -;
}
}

}

Array fnSub (Array * a, * b Array, Array * c)
{
Int m, n, I;
M=a - & gt; size;
N=a - & gt; size;
If (m>=n) {
I=m + 1;
While (n>=0) {
If (a - & gt; Array [m] & gt;=b - & gt; Array [n])
{
C - & gt; Array [I]=c - & gt; Array [I] + a - & gt; Array [m] - b - & gt; Array [n].
i--;
M -;
N -;
}
The else
{
C - & gt; Array [I]=a - & gt; Array [m] + 10 - b - & gt; Array [n].
i--;
M -;
N -;
A - & gt; Array [m]=a - & gt; Array [m] - 1;
}
}
for(; I>=0; I -)
{
C - & gt; Array [I]=a - & gt; Array [m];
M -;
}
}
The else {
I=n + 2;
While (m>=0) {
If (b - & gt; Array [n] & gt;=a - & gt; Array [m])
{
C - & gt; Array [I]=c - & gt; Array [I] + b - & gt; Array [n] - a - & gt; Array [m];
i--;
M -;
N -;
}
The else
{
C - & gt; Array [I]=b - & gt; Array [n] + 10 - a - & gt; Array [m];
i--;
M -;
N -;
B - & gt; Array [n]=b - & gt; Array [n] - 1;
}
}
for(; I> 0; I -)
{
C - & gt; Array [I]=b - & gt; Array [n].
N -;
}
C - & gt; Array [0]='-';
}
}

Array fnPrint (Array * a)
{
int i;
If (a - & gt; Array [0]=='0') {
for(i=1; A - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related