Home > Back-end >  A sophomore students, made up a substring procedures, look not to understand error. A great god
A sophomore students, made up a substring procedures, look not to understand error. A great god

Time:10-01

Source: # include "stdafx. H"
# include "iostream"
using namespace std;
# define MAXLEN 200
Char * strsub (char * s, int, int len)
{
Int j, slen;
The static char t [MAXLEN];
Slen=strlen (s);
If (i> Slen | | i<1 | | len<0 | | len> Slen - I + 1)
Cout & lt; <"Wrong, please input again!!!!!! ";
return 0;
For (j=0; J & lt; Len. J++)
T [j]=s [I + j - 1);
T [j]='\ 0';
Return (t);
}
Void main ()
{
Int len, I;
Char s [MAXLEN];
Char * p;
Cout & lt; <"Please input the original string:";
cin> s;
Cout & lt; <"Please input the original position of the substring:";
cin> i;
Cout & lt; <"Please input the length of the substring:";
cin> Len.
P=strsub (s, I, len);
Cout & lt;

}



Error: 0 x01236571 first chance exception (in ConsoleApplication2. Exe) : 0 xc0000005: access conflict while reading position 0 x00000000,
0 x01236571 in untreated exception (in ConsoleApplication2. Exe) : 0 xc0000005: access conflict while reading position 0 x00000000,

0 x01236571 first chance exception (in ConsoleApplication2. Exe) : 0 xc0000005: access conflict while reading position 0 x00000000,
0 x01236571 in untreated exception (in ConsoleApplication2. Exe) : 0 xc0000005: access conflict while reading position 0 x00000000,

Program "[7804] ConsoleApplication2. Exe" have withdrawn, the return value is zero (0 x0),

CodePudding user response:

 # include & lt; Iostream> 
# include & lt; String>

using namespace std;
# define MAXLEN 200
Char * strsub (char * s, int, int len)
{
Int j, slen;
The static char t [MAXLEN];
Slen=strlen (s);
If (i> Slen | | i<1 | | len<0 | | len> Slen - I + 1) {
Cout & lt; <"Wrong, please input again!!!!!! ";
return 0;
}
For (j=0; J & lt; Len. J++)
T [j]=s [I + j - 1);
T [j]='\ 0';
Return (t);
}
Int main ()
{
Int len, I;
Char s [MAXLEN];
Char * p;
Cout & lt; <"Please input the original string:";
cin> s;
Cout & lt; <"Please input the original position of the substring:";
cin> i;
Cout & lt; <"Please input the length of the substring:";
cin> Len.
P=strsub (s, I, len);
Cout & lt;

}

  • Related