Home > Software engineering >  Why g output not to come out, calculation was wrong?
Why g output not to come out, calculation was wrong?

Time:09-26

#include
#include
Void main () {


Char a [10]={' s', 'a', 'w'}, b [10]={' g ', 'w', 'f'};

int i;

For (I=strlen (a) + 1; i<10; I++) {

A [I]=[I - b strlen (a)];
}
For (I=0; i<10; I++) {


Printf (" % c ", a [I]);
}
printf("\n");
}

CodePudding user response:

 a=b [I] [I - strlen (a) - 1]. 


You began value b [1], so will not output 'g'

CodePudding user response:

Char a [10]={' s', 'a', 'w'};//put the remaining seven compiler to 0, a first="saw"
Char [10] b={' g ', 'w', 'f'};//b="GWF
"int i;
//
For (I=strlen (a); i<10; I++)//so strlen here is legal (a)

CodePudding user response:

Note that
Printf (" % c ", 0);//="a"
Use the
Printf (" % 02 x, 0).//="00"

CodePudding user response:

Learn to debug it

The debugged and so many great god knew the problem was incredibly so hard to answer

CodePudding user response:

For (I=strlen (a) + 1; i<10; I++) {//strlen (a)=3, 4 you start is wrong, don't + 1

A [I]=[I - b strlen (a)];
}

CodePudding user response:

In addition, the char a [10]={' s', 'a', 'w'}, b [10]={' g ', 'w', 'f'}; This definition to change
Char a [10]={' s', 'a', 'w', 0}, b [10]={' g ', 'w', 'f', 0};
  • Related