Home > Back-end >  Novice small white turn to a problem
Novice small white turn to a problem

Time:09-18

Subject requirement is that the Insert function will Insert another string a string in the specified location, Insert part use {} name, but I was in my program '} ', but still output the garbled words, changed the ASC code also not line,

New people for help!!!!!!
Here is my code, if there is a problem where hope bosses can point to,
 # include & lt; Iostream> 
using namespace std;

Int the Insert (char * dest, char * SRC, int pos);

Char * S1, S2.

Int main (int arg c, char * argv [])
{
Char [80] s1 and s2 [80].
Int n, len;

S1=S1;
S2=S2;

Cout & lt; <"Dest:";
Cin & gt;> S1.
Cout & lt; <"SRC";
Cin & gt;> S2.
Cout & lt; <"Pos:";
Cin & gt;> n;

Len=Insert (S1, S2, n); Write://in the complete program calls the Insert function,


Cout & lt; <"The output:" & lt; return 0;
}

Int the Insert (char * dest, char * SRC, int pos)
{
int i, j;
Char \ [80].

\ [0]='} ';
For (I=pos, j=1; i <=strlen (dest); I++ j++)
[j]=temp dest [I];
Dest (pos)=123;
For (I=0, j=pos + 1; i <=strlen (SRC) - 1; I++ j++)
Dest [j]=SRC [I];
Dest [j + 1)='\ 0';

Strcat (dest, temp);

S1=dest;

Return strlen (dest);
}

CodePudding user response:

Dest [j + 1)='\ 0'; To dest [j]='\ 0';//note for circulation after the location of j j, so dest [j]='\ 0'; Is correct, dest [m + 1] can cause dest [j] is a garbage characters, so will the code

CodePudding user response:

reference 1st floor qybao response:
dest [j + 1)='\ 0'; To dest [j]='\ 0';//note for circulation after the location of j j, so dest [j]='\ 0'; Is correct, dest [m + 1] can cause dest [j] is a garbage characters, so will the code

Thank you very much. Bosses, didn't see such a simple question, it seems more to learn,
  • Related