Home > Back-end >  C language - inverse order elements, cycle a problem part, please help!!!!! Detailed instructions be
C language - inverse order elements, cycle a problem part, please help!!!!! Detailed instructions be

Time:12-14

Problem (1) every time the input the correct elements such as a, after the if statement into will print the else statement in it, and I don't know what went wrong?
Look at the if condition I think logically ok?? Seeking guidance!!
(2) input illegal elements, such as ", "the cycle then becomes three times, then enter" ", circulation becomes twice,
I don't know why, the problem of other program is always met, what reason is this excuse me??
 # include & lt; stdio.h> 
Void inversion ();
Int main ()
{
Char a [100]={' 0 '};
char c;
Int I=0, length=0;
Do
{
Printf (" \ nplease enter a letter (if want to exit, enter '/') : ");
The scanf (" % c ", & amp; C);
If (c>='a' & amp; & C<='z' | | c>='A' & amp; & C{
A [I]=c;
i++;
}
The else
{
Printf (" \ nError! Both please enter a 'letter'!" );
}

} while (c!='/' & amp; & i<100);

If (a [0]=='/')
Printf (" \ n input element, unable to reverse ");
Else if (a [1]=='/')
Printf (" \ n % c there is only one element, not reverse place ", a [0]).
The else
{
Length=I;
Inversion (a, length);
Printf (" element inverse to: \ n ");
for(i=0; iPrintf (" % c ", a [I]);
}

}
Void inversion (char [], int length)
{
Int p, q;
Char t;
P=0; Q=length - 1;
While (p{
T=a, [p].
A [p]=a, [q].
A [q]=t;
p++;
Q -;
}
}



The problem is (1) the screenshot


The problem is (2) the screenshot

Now this thank you!!!!!
  • Related