访问冲突错误 [英] Access violation error

查看:160
本文介绍了访问冲突错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我之前提供的代码中,问题的原因是

访问冲突错误。当我运行调试器时,它会跳到我的b $ b只能假设我的代码的编译器版本。我不知道

问题出在代码中。任何人都可以通过它运行它

自己的编译器请告诉我问题出在哪里和什么。

#include< iostream>

#包括< iomanip>

#include< fstream>

#include< cstring>

#include< cstdlib>

使用命名空间std;


struct crecord {

long customercode [5];

char customername [21 ];

char customeraddress [61];

双倍顾客余额;

双倍信贷限额;


};

crecord Newcrecord;


struct irrecord {

long customercode [5];

long partnum [5];

long issue_rec;


};

irrecord Newirrecord;


struct drecord {

long customercode [5];

};

drecord Newdrecord;



////////////////////////////////////////// //////////////////

bool IRRecordvalidlength(char *记录)

{

int len;


开关(记录[0])

{

case''i'':

case''I'':

case''r'':

case''R'':


len = strlen(记录);

if(len< 17)

返回false;

休息;

}


返回true;

};

//////////////////////////////////////////// ////////////////

bool CRecordvalidlength(char * record)

{

int len ;


开关(记录[0])

{

case''c'':

case''C'':


len = strlen(记录);

if(len <103)

返回false;

休息;


}

返回true;


}

////////////////////////////////////////// //////////////

bool Drecordvalidlength(char * record)

{

int len;


开关(记录[0])

{

case''d'':

case''D'':


len = strlen(记录);

if(len< 7)

返回false;

break;


}

返回true;

}

///////////////// ////////////////////////////////////////////////// /////////

bool CheckAllNumeric(const char * string)

{

int Len = strlen(string);


for(int i = 0;我<莱恩; ++ i)

if(!isdigit(string [i]))

返回false;


返回true; < br $>
}


////////////////////////////// //////////////////////////////////////////////

bool CheckFloatNumber(const char * string)

{

int Len = strlen(string);


for (int i = 0; i< Len; ++ i)

if(!isdigit(string [i])&&

string [i]! =''。'')

返回false;


返回true;

}


////////////////////////////////////////////// /////////////////////////////

irrecord * CheckDigit(ofstream& prnfile,ofstream& validdata,char *

记录)

{

字符代码[5];

int weightingfactor = 5;

int checkdigit;

int余数;

int check1;


strncpy(代码,& record [ 2],6);

code [5] =''\ 0'';

Newirrecord.customer code [5] = atol(code);

for(int i = 0;我< 6; ++ i)

check1 + = Newirrecord.customercode [i] * weightingfactor;

weightingfactor - ;


remainder = check1%11;


checkdigit = 11 - 余数;


if(!Newirrecord.customercode [5] == checkdigit){

prnfile<< 无效的客户编号;

prnfile<<记录<<结束;

}

返回false;


if(Newirrecord.customercode [5] == checkdigit){


validdata.write((char *)record,Newirrecord.customercode [5]);

}


} < br $>
/////////////////////////////////////////// //////////////////////////////////////////


drecord * checkdigit(ofstream& prnfile,ofstream& validdata,char *

记录)

{

char code [5] ;

int weightingfactor = 5;

int checkdigit;

int余数;

int check1;


strncpy(代码,&记录[2],5);

代码[5] =''\ 0'';

Newdrecord.customercode [5] = atol(代码);

for(int i = 0; i< 4; ++ i)

check1 + = Newdrecord .customercode [i] *加权因子;

加权因子 - ;


余数= check1%11;


checkdigit = 11 - 余数;


if(!Newdrecord.customerc ode [5] == checkdigit){

prnfile<< 无效的客户编号;

prnfile<<记录<<结束;

}

返回false;


validdata.write((char *)record,Newdrecord.customercode [5] );

}

/////////////////////////////// /////////////////////////////////////////////////


/////////////////////////////////////// /////////////////////////////////////////

crecord * checkdigitforcustomercode(ofstream& prnfile,ofstream&

validdata,char * record)

{

char code [5];

int weightingfactor = 5;

int checkdigit;

int remaining;

int check1;


strncpy(代码,&记录[2],5);

代码[5] =''\ 0'';

Newcrecord.customercode [5] = atol(代码);

for(int i = 0; i< 6; ++ i)

check1 + = Newcrecord.customercode [i] *加权因子;

加权因子 - ;


余数= check1%11;


checkdigit = 11 - 余数;


if(check digit == 11){

checkdigit =''X'';

}

else

if( checkdigit = checkdigit = 10){

checkdigit =''0'';

}

if(! Newcrecord.customercode [5] == checkdigit){

prnfile<< 无效的客户编号;

prnfile<<记录<< endl;

}

返回false;


validdata.write((char *)record,Newcrecord.customercode [5] );


}

/////////////////////////// ////////////////////////////////////////////////// ///////

irrecord * checkdigitforpartnum(ofstream& prnfile,ofstream& validdata,

char * record)

{

int weightingfactor2;

char part_num [6];

int partnumcheck;

int produce;

int holdall;


strncpy(part_num,& record [7],6);

part_num [6] =''\ 0 '';

Newirrecord.partnum [6] = atol(part_num);


weightingfactor2 = 6;


for(int i = 0; i< 6; ++ i)

holdall + = Newirrecord.partnum [i] * weightingfactor2;

weightingfactor2 - ;


产生= holdall%11;


partnumcheck = 11 - 产生;

if(partnumcheck == 11) {

partnumcheck =' X'';

}

其他

if(partnumcheck = 10){

partnumcheck =''0 '';

}


if(! Newirrecord.partnum [5] == partnumcheck){

prnfile<< 无效:部件号不正确,检查数字无效;

prnfile<<记录<<结束;

}

返回false;


validdata.write((char *)record,Newirrecord.partnum [5] );


}


/////////////////////// ////////////////////////////////////////////////// ///////////

bool CheckAddress(const char * alpha)

{


int max_alpha = 60;


for(int i = 0; i< max_alpha; ++ i)

if(!isalpha(alpha [i])& ;&(alpha [i]!='';;;;'')&&(alpha [i]!=

''''))

if(Newcrecord.customeraddress [61]!=(alpha [i]))

返回false;


返回true;

}

////////////////////////////////////// /////////////////////////////////////////

bool Processcrecord(ofstream& prnfile,ofstream& validdata,char *

记录)

{

char customercode [6];

char balance [10];

char limit [10];

crecord Newcrecord;
< br $>
//

//处理客户代码

//

strncpy(customercode,& record [1 ],5);

customercode [5] =''\ 0'';

if(!CheckAllNumeric(customercode)){

prnfile<< 无效:客户代码需要全部数字

[位置3 - 5个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

Newcrecord.customercode [5] = atol(customercode);


//

//处理客户名称

//

strncpy(Newcrecord.customername,& record [7] ,20);

Newcrecord.customername [20] =''\ 0'';


//

/ /处理客户地址

//

strncpy(Newcrecord.customeraddress,& record [27],61);

Newcrecord.customeraddress [61] =''\ 0'';


//处理客户余额

//

strncpy(余额,&记录[87],9);

余额[9] =''\ 0'';

if(!CheckFloatNumber(余额)){

prnfile<< 无效:余额字段不是有效数字[位置

88 - 9个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

Newcrecord.customerbalance = atof(余额);

validdata.write ((char *)记录,Newcrecord.customerbalance);


//

//处理客户限制

//

strncpy(限制,&记录[97],9);

limit [9] =''\''';

if(!CheckFloatNumber(limit)){

prnfile<< 无效:限制字段不是有效数字[位置

98 - 9个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

Newcrecord.creditlimit = atof(limit);


validdata.write((char *)record,Newcrecord.creditlimit);


返回true;


}


//////////////////////////////////////////// ///////////


bool processdrecord(char * record,ofstream& prnfile,ofstream&

validdata)

{

drecord Newdrecord;

char customercode [5];


strncpy(customercode,& record [ 1],5);

customercode [5] =''\ 0'';

if(!CheckAllNumeric(customercode)){

prnfile<< 无效:D记录客户代码不包含

数字格式;

prnfile<<记录<< endl;

返回false;

}

Newdrecord.customercode [5] = atol(customercode);


validdata.write((char *)record,Newdrecord.customercode [5]);

返回true;

}


///////////////////////////////////////// ////////////////////////////////

bool ProcessIRecord(ofstream& prnfile,ofstream& validdata ,char *

记录)

{

char customer [6];

char issue_rec [5];

char part [6];


long customer_code;

long issuerec;

long partnum [6];


//

//处理客户代码

//

strncpy(customer,& record [2],5);

customer [6] =''\ 0'';

if(!CheckAllNumeric(customer) ){

prnfile<< 无效:客户代码需要全部数字

[位置3 - 5个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

customer_code = atol(客户);


/ /

//处理零件编号

//

strncpy(part,& record [7],6);

part [6] =''\ 0'';

if(!CheckAllNumeric(part)){

prnfile<< 无效:部件号必须全部为数字[位置

9 - 6个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

partnum [6] = atol(部分);


validdata.write((char *)record,partnum [6]);


返回true;


//

//处理第三个数字

//

strncpy(issue_rec,& record [13],5);

issue_rec [5] =''\ 0'';

if(!CheckAllNumeric(issue_rec)){

prnfile<< 无效:代码需要全部为数字[位置16

- 4个字符]:\ n" ;;

prnfile<<记录<< endl;

返回false;

}

issuerec = atol(issue_rec);

返回true;

}


/////////////////////////////// //////////////////////////////////////////

int main()

{

const char infile [] =" A:\\514650TD.txt" ;;

const char outfile [] =" A:\\514650VD.DAT" ;;

const char printerfile [] =" A:\\514650.TXT" ;;


int max = 256;



ifstream testdata;

ofstream prnfile;

ofstream validdata;


testdata.open(" A:\\514650TD.txt",ios :: in) ;

if(!testdata)

{

cout<<""该文件尚不存在 << infile<< endl;

返回EXIT_FAILURE;

}


validdata.open(" A:\\514650.DAT" ,ios :: out | ios :: binary);

if(!validdata.is_open())

{

cout<< "该文件无法打开 << outfile<< endl;

返回EXIT_FAILURE;

}


prnfile.open(" A:\\\ \\ _514650.TXT",ios :: out);

if(!prnfile)

{

cout<< 无法打开文件 << prnfile<< endl;

返回EXIT_FAILURE;

};

prnfile<< C_RECORD,I-R RECORD,D_RECORD ERRORS << endl;


while(testdata.getline(temp1,sizeof(temp1))){

if(!CRecordvalidlength(temp1)){

prnfile<<"无效:记录不包含足够的字符:\ n" ;;

prnfile<< temp1<< endl;

继续;

}

if(!IRRecordvalidlength(temp1)){

prnfile<< 无效:记录不包含足够的字符:\ n";

prnfile<< temp1<< endl;

继续;

}

if(!Drecordvalidlength(temp1)){

prnfile<< 无效:记录不包含足够的字符:\ n";

prnfile<< temp1<<结束;

继续;

};


开关(temp1 [0])

{

case''c'':

case''C'':

Processcrecord(prnfile,validdata,temp1);

checkdigitforcustomercode(prnfile,validdata,temp1);

休息;


case''我'':

case''我'':

case''r'':

case''R'':

ProcessIRecord(prnfile, validdata,temp1);

CheckDigit(prnfile,validdata,temp1);

checkdigitforpartnum(prnfile,validdata,temp1);

break;


case''d'':

case''D'':

processdrecord(temp1,prnfile,validdata);

checkdigit(prnfile,validdata,temp1);

break;

默认值:prnfile<< 未知记录;

prnfile<< temp1<<结束;

};


}

testdata.close();

validdata.close ();

prnfile.close();

返回EXIT_SUCCESS;


};

In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don''t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;

struct crecord {
long customercode[5];
char customername[21];
char customeraddress[61];
double customerbalance;
double creditlimit;

};
crecord Newcrecord;

struct irrecord {
long customercode[5];
long partnum[5];
long issue_rec;

};
irrecord Newirrecord;

struct drecord {
long customercode[5];
};
drecord Newdrecord;


////////////////////////////////////////////////////////////
bool IRRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case''i'':
case''I'':
case''r'':
case''R'':

len= strlen(record);
if(len<17)
return false;
break;
}

return true;
};
////////////////////////////////////////////////////////////
bool CRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case''c'':
case''C'':

len = strlen(record);
if(len<103)
return false;
break;

}
return true;

}
////////////////////////////////////////////////////////
bool Drecordvalidlength( char* record )
{
int len;

switch(record[0])
{
case''d'':
case''D'':

len = strlen(record);
if(len<7)
return false;
break;

}
return true;
}
////////////////////////////////////////////////////////////////////////////
bool CheckAllNumeric( const char * string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) )
return false;

return true;
}

////////////////////////////////////////////////////////////////////////////
bool CheckFloatNumber( const char* string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) &&
string[i] != ''.'' )
return false;

return true;
}

///////////////////////////////////////////////////////////////////////////
irrecord* CheckDigit(ofstream& prnfile, ofstream& validdata, char*
record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 6);
code[5] = ''\0'';
Newirrecord.customercode[5] = atol( code );
for(int i =0; i < 6; ++i)
check1 += Newirrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(! Newirrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

if(Newirrecord.customercode[5] == checkdigit){

validdata.write((char*) record, Newirrecord.customercode[5]);
}

}
/////////////////////////////////////////////////////////////////////////////////////

drecord* checkdigit(ofstream& prnfile, ofstream& validdata, char*
record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 5);
code[5] = ''\0'';
Newdrecord.customercode[5] = atol( code );
for(int i =0; i < 4; ++i)
check1 += Newdrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(! Newdrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newdrecord.customercode[5]);
}
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
crecord* checkdigitforcustomercode( ofstream& prnfile, ofstream&
validdata, char* record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 5);
code[5] = ''\0'';
Newcrecord.customercode[5] = atol( code );
for(int i =0; i < 6; ++i)
check1 += Newcrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(checkdigit == 11){
checkdigit = ''X'';
}
else
if(checkdigit = checkdigit = 10){
checkdigit = ''0'';
}
if(! Newcrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newcrecord.customercode[5]);

}
////////////////////////////////////////////////////////////////////////////////////
irrecord* checkdigitforpartnum(ofstream& prnfile, ofstream& validdata,
char* record)
{
int weightingfactor2;
char part_num[6];
int partnumcheck;
int produce;
int holdall;

strncpy(part_num, &record[7], 6);
part_num[6] = ''\0'';
Newirrecord.partnum[6] = atol( part_num );

weightingfactor2 = 6;

for(int i=0; i < 6; ++i)
holdall += Newirrecord.partnum[i] * weightingfactor2;
weightingfactor2 --;

produce = holdall % 11;

partnumcheck = 11 - produce;
if(partnumcheck == 11){
partnumcheck = ''X'';
}
else
if(partnumcheck = 10){
partnumcheck = ''0'';
}

if(! Newirrecord.partnum[5] == partnumcheck){
prnfile<< "Invalid: Incorrect part number, check digit invalid";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newirrecord.partnum[5]);

}

////////////////////////////////////////////////////////////////////////////////////
bool CheckAddress( const char* alpha )
{

int max_alpha = 60;

for( int i = 0; i < max_alpha; ++i )
if( !isalpha( alpha[i] ) && ( alpha[i] != '';;;;'' ) && ( alpha[i] !=
'' '' ))
if(Newcrecord.customeraddress[61] != (alpha[i]))
return false;

return true;
}
///////////////////////////////////////////////////////////////////////////////
bool Processcrecord( ofstream& prnfile, ofstream& validdata, char*
record )
{
char customercode[6];
char balance[10];
char limit[10];
crecord Newcrecord;

//
// process the customer code
//
strncpy( customercode, &record[1], 5 );
customercode[5] = ''\0'';
if( !CheckAllNumeric( customercode ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customercode[5] = atol( customercode );

//
// process the customer name
//
strncpy( Newcrecord.customername, &record[7], 20 );
Newcrecord.customername[20] = ''\0'';

//
// process the customer address
//
strncpy( Newcrecord.customeraddress, &record[27], 61 );
Newcrecord.customeraddress[61] = ''\0'';


// process the customer balance
//
strncpy( balance, &record[87], 9 );
balance[9] = ''\0'';
if( !CheckFloatNumber( balance ) ) {
prnfile << "Invalid: balance field is not a valid number [position
88 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customerbalance = atof( balance );
validdata.write((char*) record, Newcrecord.customerbalance );

//
// process the customer limit
//
strncpy( limit, &record[97], 9 );
limit[9] = ''\0'';
if( !CheckFloatNumber( limit ) ) {
prnfile << "Invalid: limit field is not a valid number [position
98 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.creditlimit = atof( limit );

validdata.write((char*) record, Newcrecord.creditlimit );

return true;

}

///////////////////////////////////////////////////////

bool processdrecord( char* record, ofstream& prnfile, ofstream&
validdata )
{
drecord Newdrecord;
char customercode[5];

strncpy( customercode, &record[1], 5);
customercode[5] = ''\0'';
if(!CheckAllNumeric( customercode )){
prnfile<< "Invalid: D record customer code does not contain
numerical format";
prnfile<< record <<endl;
return false;
}
Newdrecord.customercode[5] = atol( customercode );

validdata.write((char*) record, Newdrecord.customercode[5] );
return true;
}

/////////////////////////////////////////////////////////////////////////
bool ProcessIRecord( ofstream& prnfile, ofstream& validdata, char*
record )
{
char customer[6];
char issue_rec[5];
char part[6];

long customer_code;
long issuerec;
long partnum[6];

//
// process the customer code
//
strncpy( customer, &record[2], 5 );
customer[6] = ''\0'';
if( !CheckAllNumeric( customer ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
customer_code = atol( customer );

//
// process the part number
//
strncpy( part, &record[7], 6 );
part[6] = ''\0'';
if( !CheckAllNumeric( part ) ) {
prnfile << "Invalid: part number needs to be all numeric [position
9 - 6 characters]:\n";
prnfile << record << endl;
return false;
}
partnum[6] = atol( part );

validdata.write((char*) record, partnum[6]);

return true;

//
// process the third number
//
strncpy( issue_rec, &record[13], 5 );
issue_rec[5] = ''\0'';
if( !CheckAllNumeric( issue_rec ) ) {
prnfile << "Invalid: the code needs to be all numeric [position 16
- 4 characters]:\n";
prnfile << record << endl;
return false;
}
issuerec = atol( issue_rec );
return true;
}

/////////////////////////////////////////////////////////////////////////
int main()
{
const char infile[] = "A:\\514650TD.txt";
const char outfile[] = "A:\\514650VD.DAT";
const char printerfile[] = "A:\\514650.TXT";

int max = 256;

char temp1[256];

ifstream testdata;
ofstream prnfile;
ofstream validdata;

testdata.open("A:\\514650TD.txt", ios::in);
if(!testdata)
{
cout<<"The file does not already exist" << infile << endl;
return EXIT_FAILURE;
}

validdata.open("A:\\514650.DAT", ios::out | ios::binary);
if(!validdata.is_open())
{
cout<<" The file could not be opened " << outfile <<endl;
return EXIT_FAILURE;
}

prnfile.open("A:\\514650.TXT", ios::out);
if(!prnfile)
{
cout<< "File could not be opened" << prnfile << endl;
return EXIT_FAILURE;
};
prnfile << "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;

while( testdata.getline( temp1, sizeof(temp1)) ){
if(!CRecordvalidlength( temp1 )){
prnfile<<"Invalid: record does not contain enough characters:\n";
prnfile<< temp1 <<endl;
continue;
}
if(!IRRecordvalidlength( temp1 )){
prnfile<< "Invalid: record does not contain enough characters:\n";
prnfile<< temp1 << endl;
continue;
}
if(!Drecordvalidlength( temp1 )){
prnfile<< "Invalid: record does not contain enough characters:\n";
prnfile<< temp1 << endl;
continue;
};

switch( temp1[0] )
{
case ''c'':
case ''C'':
Processcrecord( prnfile, validdata, temp1 );
checkdigitforcustomercode( prnfile, validdata, temp1);
break;

case ''i'':
case ''I'':
case ''r'':
case ''R'':
ProcessIRecord( prnfile, validdata, temp1 );
CheckDigit( prnfile, validdata, temp1 );
checkdigitforpartnum( prnfile, validdata, temp1 );
break;

case ''d'':
case ''D'':
processdrecord( temp1, prnfile, validdata );
checkdigit( prnfile, validdata, temp1 );
break;
default: prnfile<< "Unknown record";
prnfile<< temp1 << endl;
};

}
testdata.close();
validdata.close();
prnfile.close();
return EXIT_SUCCESS;

};

推荐答案

muser写道:
在我之前提供的代码中,问题的原因是
访问冲突错误。当我运行调试器时,它跳到了我只能假设我的代码的编译器版本。我不知道代码中的问题在哪里。任何人都可以通过那里运行它自己的编译器,并告诉我问题出在哪里和什么。


我不会逐行检查你的代码,但至少有一些东西会跳出来。见下文:

#include< iostream>
#include< iomanip>
#include< fstream>
#include< cstring> ;
#include< cstdlib>

使用命名空间std;

struct crecord {
long customercode [5];
char customername [21];
char customeraddress [61];
双重顾客;
双倍信贷限额;

};
crecord Newcrecord;
<结构irrecord {
long customercode [5];
long partnum [5];
long issue_rec;

};
irrecord Newirrecord;

struct drecord {
long customercode [5];
};
drecord Newdrecord;


//// ////////////////////////////////////////////////// //////
bool IRRecordvalidlength(char * record)
{
int len;

switch(记录[0])
{<案件''''':
案件''我':
案件''''':
案件''''':
len = s trlen(记录);
if(len< 17)
返回false;
break;

}

返回true;
};
////////////////////////////////////////// //////////////////
bool CRecordvalidlength(char * record)
{
int len;

转换(记录[0])
{
case''c'':
case''C'':

len = strlen(记录);
if(len< 103)
返回false;
break;

}

返回true;

}
////////////////////////////////////////////// //////////
bool Drecordvalidlength(char * record)
{
int len;

switch(record [0])
{
case''d'':
case''D'':

len = strlen(记录);
if(len< 7)
返回虚假;
休息;

}
返回true;
}
//////////// ////////////////////////////////////////////////// //////////////
bool CheckAllNumeric(const char * string)
{
int Len = strlen(string);

for(int i = 0;我<莱恩; ++ i)
if(!isdigit(string [i]))
返回false;

返回true;
}

////////////////////////////////////////////////// //////////////////////////
bool CheckFloatNumber(const char * string)
{Len / = int Len = strlen(string);

for(int i = 0; i< Len; ++ i)
if(!isdigit(string [i])&&
string [i]!=''。'')
返回false;

返回true;
}

////// ////////////////////////////////////////////////// ///////////////////
irrecord * CheckDigit(ofstream& prnfile,ofstream& validdata,char *
记录)
{
char code [5];
int weightingfactor = 5;
int checkdigit;
int remaining;
int check1;

strncpy(代码, & record [2],6);


您将6个字符复制成长度为5的数组。

code [5] =''\''';


不,`code [5]''不存在。数组中的最后一个元素是

`code [4]''(C ++中的数组是从零开始的,因此有效的索引从0到4运行
)。

Newirrecord.customercode [5] = atol(代码);

for(int i = 0; i< 6; ++ i)
check1 + = Newirrecord.customercode [i] * weightingfactor;
weightingfactor - ;

remainder = check1%11;

checkdigit = 11 - 余数;

if(!Newirrecord.customercode [5] == checkdigit){
prnfile<< 无效的客户编号;
prnfile<<记录<< endl;
}
返回false;

if(Newirrecord.customercode [5] == checkdigit){

validdata.write((char *记录,Newirrecord.customercode [5]);
}

}
///////////////////// ////////////////////////////////////////////////// //////////////

drecord * checkdigit(ofstream& prnfile,ofstream& validdata,char *
记录)
{
char code [5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code,& ;记录[2],5);
代码[5] =''\''';


同样,见上文。

Newdrecord.customercode [5] = atol(代码);

for(int i = 0; i< 4; ++ i)
check1 + = Newdrecord.customercode [i] * weightingfactor;
weightingfactor - ;

remainder = check1%11;

checkdigit = 11 - 余数;

if(!Newdrecord.customercode [5] == checkdigit){
prnfile<< 无效的客户编号;
prnfile<<记录<<返回false;

validdata.write((char *)record,Newdrecord.customercode [5]);

}
/////////////////////////////////////////////// /////////////////////////////////
///////// ////////////////////////////////////////////////// /////////////////////
crecord * checkdigitforcustomercode(ofstream& prnfile,ofstream&
validdata,char * record)
{
char code [5];
int weightingfactor = 5;
int checkdigit;
int remaining;
int check1;

strncpy(代码,& record [2],5);
代码[5] =''\ 0'';
Newcrecord.customercode [5] = atol(代码);

for(int i = 0; i< 6; ++ i)
check1 + = Newcrecord.customercode [i] * weightingfactor;
weightingfactor - ;
余数= check1%11;

checkdigit = 11 - 余数;

if(checkdigit == 11){
checkdigit =''X'';
}
否则
if(checkdigit = checkdigit = 10){
checkdigit =''0'';
}

if(! Newcrecord.customercode [5] == checkdigit){
prnfile<< 无效的客户编号;
prnfile<<记录<<返回false;

validdata.write((char *)record,Newcrecord.customercode [5]);

}
/////////////////////////////////////////////// /////////////////////////////////////
irrecord * checkdigitforpartnum(ofstream& prnfile,ofstream& ; validdata,
char * record)
{} int weightingfactor2;
char part_num [6];
int partnumcheck;
int produce;
int holdall;

strncpy(part_num,& record [7],6);
part_num [6] =''\ 0'';
Newirrecord.partnum [6] = atol(part_num);

weightingfactor2 = 6;

for(int i = 0; i< 6; ++ i)
holdall + = Newirrecord.partnum [i] * weightingfactor2;
weightingfactor2 - ;

产生= holdall%11;

partnumcheck = 11 - 产生;

if(partnumcheck == 11){
partnumcheck =''X'';
}

if(partnumcheck = 10){
partnumcheck =''0'';
}

if(!Newirrecord.partnum [5] == partnumcheck){
prnfile<< 无效:部件号不正确,检查数字无效;
prnfile<<记录<<返回false;

validdata.write((char *)record,Newirrecord.partnum [5]);

} <
/////////////////////////////////////////// /////////////////////////////////////////
bool CheckAddress(const char * alpha)
对于(int i = 0; i< max_alpha; ++ i)
int max_alpha = 60;

如果(!isalpha(alpha [i])&&(alpha [i]!='';;;;'')&&(alpha [i]!=
''''))
if(Newcrecord.customeraddress [61]!=(alpha [i]))
返回false;

返回true;

}
//////////////////////////////////////////////// ///////////////////////////////

bool Processcrecord(ofstream& prnfile,ofstream& validdata, char *
记录)
{char customercode [6];
char balance [10];
char limit [10];

crecord Newcrecord;

//
//处理客户代码
//
strncpy(c ustomercode,& record [1],5);
customercode [5] =''\ 0'';
if(!CheckAllNumeric(customercode)){
prnfile<< ; 无效:客户代码需要全部数字
[位置3 - 5个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
Newcrecord.customercode [5] = atol(customercode);

//
//处理客户名称
//
strncpy(Newcrecord.customername,& record [7],20);
Newcrecord.customername [20] =''\ 0'';
< br //> //
//处理客户地址
//
strncpy(Newcrecord.customeraddress,& record [27],61);
Newcrecord.customeraddress [61 ] =''\''';

//处理客户余额
//
strncpy(余额,&记录[87],9 );
balance [9] =''\ 0'';
if(!CheckFloatNumber(balance)){
prnfile<< 无效:余额字段不是有效数字[位置
88 - 9个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
Newcrecord.customerbalance = atof(balance);

validdata.write((char *)record,Newcrecord.customerbalance);

//处理客户限制
//
strncpy(限制,&记录[97],9);
限制[ 9] =''\''';
if(!CheckFloatNumber(limit)){
prnfile<< 无效:限制字段不是有效数字[位置
98 - 9个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
Newcrecord.creditlimit = atof(limit);

validdata.write((char *)record,Newcrecord.creditlimit);

返回true;

}
////////////////////// /////////////////////////////////

bool processdrecord(char * record,ofstream& prnfile,ofstream&
validdata)
{
drecord Newdrecord;
char customercode [5];

strncpy(customercode,& record [1] ,5);
customercode [5] =''\ 0'';
if(!CheckAllNumeric(customercode)){
prnfile<< 无效:D记录客户代码不包含
数字格式;
prnfile<<记录<< endl;
返回false;
}
Newdrecord.customercode [5] = atol(customercode);

validdata.write((char * )记录,Newdrecord.customercode [5]);

返回true;
}
/////////////// ////////////////////////////////////////////////// ////////
bool ProcessIRecord(ofstream& prnfile,ofstream& validdata,char *
记录)

char customer [6];
char issue_rec [5];
char part [6];

long customer_code;
long issuerec;
long partnum [6];
//
//处理客户代码
//
strncpy(客户,&记录[2],5);
客户[6] =''\''';
if(!CheckAllNumeric(customer)){
prnfile<< 无效:客户代码需要全部数字
[位置3 - 5个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
customer_code = atol(客户);

//
//处理部件号
/ /
strncpy(part,& record [7],6);
part [6] =''\ 0'';
if(!CheckAllNumeric(part)){
prnfile<< 无效:部件号必须全部为数字[位置
9 - 6个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
partnum [6] = atol(部分);

validdata.write((char *)record,partnum [6] );

返回true;

//
//处理第三个数字
//
strncpy(issue_rec,& record [13],5);
issue_rec [5] =''\ 0'';
if(!CheckAllNumeric(issue_rec)){
prnfile<< 无效:代码需要全部为数字[位置16
- 4个字符]:\ n" ;;
prnfile<<记录<< endl;
返回false;
}
issuerec = atol(issue_rec);

返回true;
}

/ ////////////////////////////////////////////////// //////////////////////

int main()
{
const char infile [] =" ; A:\\514650TD.txt" ;;
const char outfile [] =" A:\\514650VD.DAT" ;;
const char printerfile [] =" A:\\ \\\514650.TXT" ;;

int max = 256;

char temp1 [256];

ifstream testdata;
ofstream prnfile;
ofstream validdata;

testdata.open(" A:\\514650TD.txt",ios :: in);
if(!testdata)
{
cout<<"该文件尚不存在 << infile<< endl;
返回EXIT_FAILURE;
}

validdata.open(" A:\\514650.DAT",ios :: out | ios :: binary);
if(!validdata.is_open())
{
cout<<"该文件无法打开 << outfile<< endl;
返回EXIT_FAILURE;
}

prnfile.open(" A:\\514650.TXT",ios :: out);
if(!prnfile)
{
cout<< 无法打开文件 << prnfile<< endl;
return EXIT_FAILURE;
};

prnfile << "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;

while( testdata.getline( temp1, sizeof(temp1)) ){
\t if(!CRecordvalidlength( temp1 )){
\t\t prnfile<<"Invalid: record does not contain enough characters:\n";
\t\t prnfile<< temp1 <<endl;
\t\t continue;
\t }
\t if(!IRRecordvalidlength( temp1 )){
\t\t prnfile<< "Invalid: record does not contain enough characters:\n";
\t\t prnfile<< temp1 << endl;
\t\t continue;
\t }
\t if(!Drecordvalidlength( temp1 )){
\t\t prnfile<< "Invalid: record does not contain enough characters:\n";
\t\t prnfile<< temp1 << endl;
\t\t continue;
\t };

\t switch( temp1[0] )
\t {
\t case ’’c’’:
\t case ’’C’’:
\t\t Processcrecord( prnfile, validdata, temp1 );
\t\t checkdigitforcustomercode( prnfile, validdata, temp1);
\t\t break;

\t case ’’i’’:
\t case ’’I’’:
\t case ’’r’’:
\t case ’’R’’:
\t\t ProcessIRecord( prnfile, validdata, temp1 );
\t\t CheckDigit( prnfile, validdata, temp1 );
\t\t checkdigitforpartnum( prnfile, validdata, temp1 );
\t\t break;

\t case ’’d’’:
\t case ’’D’’:
\t\t processdrecord( temp1, prnfile, validdata );
\t\t checkdigit( prnfile, validdata, temp1 );
\t\tbreak;
\t default: prnfile<< "Unknown record";
\t\t prnfile<< temp1 << endl;
\t };

}
testdata.close();
validdata.close();
prnfile.close();

return EXIT_SUCCESS;

};
In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don''t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is.
I''m not going to go through your code line by line, but at least a
couple of things jump right out. See below:


#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;

struct crecord {
long customercode[5];
char customername[21];
char customeraddress[61];
double customerbalance;
double creditlimit;

};
crecord Newcrecord;

struct irrecord {
long customercode[5];
long partnum[5];
long issue_rec;

};
irrecord Newirrecord;

struct drecord {
long customercode[5];
};
drecord Newdrecord;


////////////////////////////////////////////////////////////
bool IRRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case''i'':
case''I'':
case''r'':
case''R'':

len= strlen(record);
if(len<17)
return false;
break;
}

return true;
};
////////////////////////////////////////////////////////////
bool CRecordvalidlength(char* record)
{
int len;

switch(record[0])
{
case''c'':
case''C'':

len = strlen(record);
if(len<103)
return false;
break;

}
return true;

}
////////////////////////////////////////////////////////
bool Drecordvalidlength( char* record )
{
int len;

switch(record[0])
{
case''d'':
case''D'':

len = strlen(record);
if(len<7)
return false;
break;

}
return true;
}
////////////////////////////////////////////////////////////////////////////
bool CheckAllNumeric( const char * string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) )
return false;

return true;
}

////////////////////////////////////////////////////////////////////////////
bool CheckFloatNumber( const char* string )
{
int Len = strlen( string );

for( int i = 0; i < Len; ++i )
if( !isdigit( string[i] ) &&
string[i] != ''.'' )
return false;

return true;
}

///////////////////////////////////////////////////////////////////////////
irrecord* CheckDigit(ofstream& prnfile, ofstream& validdata, char*
record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 6);
Your copying 6 `char''s into an array of length 5.
code[5] = ''\0'';
No, `code[5]'' does not exist. The last element in the array is
`code[4]'' (arrays in C++ are zero-based, hence valid indices run
from 0 to 4).
Newirrecord.customercode[5] = atol( code );
for(int i =0; i < 6; ++i)
check1 += Newirrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(! Newirrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

if(Newirrecord.customercode[5] == checkdigit){

validdata.write((char*) record, Newirrecord.customercode[5]);
}

}
/////////////////////////////////////////////////////////////////////////////////////

drecord* checkdigit(ofstream& prnfile, ofstream& validdata, char*
record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 5);
code[5] = ''\0'';
Similarly, see above.
Newdrecord.customercode[5] = atol( code );
for(int i =0; i < 4; ++i)
check1 += Newdrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(! Newdrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newdrecord.customercode[5]);
}
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
crecord* checkdigitforcustomercode( ofstream& prnfile, ofstream&
validdata, char* record )
{
char code[5];
int weightingfactor = 5;
int checkdigit;
int remainder;
int check1;

strncpy(code, &record[2], 5);
code[5] = ''\0'';
Newcrecord.customercode[5] = atol( code );
for(int i =0; i < 6; ++i)
check1 += Newcrecord.customercode[i] * weightingfactor;
weightingfactor --;

remainder = check1 % 11;

checkdigit = 11 - remainder;

if(checkdigit == 11){
checkdigit = ''X'';
}
else
if(checkdigit = checkdigit = 10){
checkdigit = ''0'';
}
if(! Newcrecord.customercode[5] == checkdigit){
prnfile<< "Invalid customer number";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newcrecord.customercode[5]);

}
////////////////////////////////////////////////////////////////////////////////////
irrecord* checkdigitforpartnum(ofstream& prnfile, ofstream& validdata,
char* record)
{
int weightingfactor2;
char part_num[6];
int partnumcheck;
int produce;
int holdall;

strncpy(part_num, &record[7], 6);
part_num[6] = ''\0'';
Newirrecord.partnum[6] = atol( part_num );

weightingfactor2 = 6;

for(int i=0; i < 6; ++i)
holdall += Newirrecord.partnum[i] * weightingfactor2;
weightingfactor2 --;

produce = holdall % 11;

partnumcheck = 11 - produce;
if(partnumcheck == 11){
partnumcheck = ''X'';
}
else
if(partnumcheck = 10){
partnumcheck = ''0'';
}

if(! Newirrecord.partnum[5] == partnumcheck){
prnfile<< "Invalid: Incorrect part number, check digit invalid";
prnfile<< record << endl;
}
return false;

validdata.write((char*) record, Newirrecord.partnum[5]);

}

////////////////////////////////////////////////////////////////////////////////////
bool CheckAddress( const char* alpha )
{

int max_alpha = 60;

for( int i = 0; i < max_alpha; ++i )
if( !isalpha( alpha[i] ) && ( alpha[i] != '';;;;'' ) && ( alpha[i] !=
'' '' ))
if(Newcrecord.customeraddress[61] != (alpha[i]))
return false;

return true;
}
///////////////////////////////////////////////////////////////////////////////
bool Processcrecord( ofstream& prnfile, ofstream& validdata, char*
record )
{
char customercode[6];
char balance[10];
char limit[10];
crecord Newcrecord;

//
// process the customer code
//
strncpy( customercode, &record[1], 5 );
customercode[5] = ''\0'';
if( !CheckAllNumeric( customercode ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customercode[5] = atol( customercode );

//
// process the customer name
//
strncpy( Newcrecord.customername, &record[7], 20 );
Newcrecord.customername[20] = ''\0'';

//
// process the customer address
//
strncpy( Newcrecord.customeraddress, &record[27], 61 );
Newcrecord.customeraddress[61] = ''\0'';


// process the customer balance
//
strncpy( balance, &record[87], 9 );
balance[9] = ''\0'';
if( !CheckFloatNumber( balance ) ) {
prnfile << "Invalid: balance field is not a valid number [position
88 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.customerbalance = atof( balance );
validdata.write((char*) record, Newcrecord.customerbalance );

//
// process the customer limit
//
strncpy( limit, &record[97], 9 );
limit[9] = ''\0'';
if( !CheckFloatNumber( limit ) ) {
prnfile << "Invalid: limit field is not a valid number [position
98 - 9 characters]:\n";
prnfile << record << endl;
return false;
}
Newcrecord.creditlimit = atof( limit );

validdata.write((char*) record, Newcrecord.creditlimit );

return true;

}

///////////////////////////////////////////////////////

bool processdrecord( char* record, ofstream& prnfile, ofstream&
validdata )
{
drecord Newdrecord;
char customercode[5];

strncpy( customercode, &record[1], 5);
customercode[5] = ''\0'';
if(!CheckAllNumeric( customercode )){
prnfile<< "Invalid: D record customer code does not contain
numerical format";
prnfile<< record <<endl;
return false;
}
Newdrecord.customercode[5] = atol( customercode );

validdata.write((char*) record, Newdrecord.customercode[5] );
return true;
}

/////////////////////////////////////////////////////////////////////////
bool ProcessIRecord( ofstream& prnfile, ofstream& validdata, char*
record )
{
char customer[6];
char issue_rec[5];
char part[6];

long customer_code;
long issuerec;
long partnum[6];

//
// process the customer code
//
strncpy( customer, &record[2], 5 );
customer[6] = ''\0'';
if( !CheckAllNumeric( customer ) ) {
prnfile << "Invalid: customer code needs to be all numeric
[position 3 - 5 characters]:\n";
prnfile << record << endl;
return false;
}
customer_code = atol( customer );

//
// process the part number
//
strncpy( part, &record[7], 6 );
part[6] = ''\0'';
if( !CheckAllNumeric( part ) ) {
prnfile << "Invalid: part number needs to be all numeric [position
9 - 6 characters]:\n";
prnfile << record << endl;
return false;
}
partnum[6] = atol( part );

validdata.write((char*) record, partnum[6]);

return true;

//
// process the third number
//
strncpy( issue_rec, &record[13], 5 );
issue_rec[5] = ''\0'';
if( !CheckAllNumeric( issue_rec ) ) {
prnfile << "Invalid: the code needs to be all numeric [position 16
- 4 characters]:\n";
prnfile << record << endl;
return false;
}
issuerec = atol( issue_rec );
return true;
}

/////////////////////////////////////////////////////////////////////////
int main()
{
const char infile[] = "A:\\514650TD.txt";
const char outfile[] = "A:\\514650VD.DAT";
const char printerfile[] = "A:\\514650.TXT";

int max = 256;

char temp1[256];

ifstream testdata;
ofstream prnfile;
ofstream validdata;

testdata.open("A:\\514650TD.txt", ios::in);
if(!testdata)
{
cout<<"The file does not already exist" << infile << endl;
return EXIT_FAILURE;
}

validdata.open("A:\\514650.DAT", ios::out | ios::binary);
if(!validdata.is_open())
{
cout<<" The file could not be opened " << outfile <<endl;
return EXIT_FAILURE;
}

prnfile.open("A:\\514650.TXT", ios::out);
if(!prnfile)
{
cout<< "File could not be opened" << prnfile << endl;
return EXIT_FAILURE;
};
prnfile << "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;

while( testdata.getline( temp1, sizeof(temp1)) ){
if(!CRecordvalidlength( temp1 )){
prnfile<<"Invalid: record does not contain enough characters:\n";
prnfile<< temp1 <<endl;
continue;
}
if(!IRRecordvalidlength( temp1 )){
prnfile<< "Invalid: record does not contain enough characters:\n";
prnfile<< temp1 << endl;
continue;
}
if(!Drecordvalidlength( temp1 )){
prnfile<< "Invalid: record does not contain enough characters:\n";
prnfile<< temp1 << endl;
continue;
};

switch( temp1[0] )
{
case ''c'':
case ''C'':
Processcrecord( prnfile, validdata, temp1 );
checkdigitforcustomercode( prnfile, validdata, temp1);
break;

case ''i'':
case ''I'':
case ''r'':
case ''R'':
ProcessIRecord( prnfile, validdata, temp1 );
CheckDigit( prnfile, validdata, temp1 );
checkdigitforpartnum( prnfile, validdata, temp1 );
break;

case ''d'':
case ''D'':
processdrecord( temp1, prnfile, validdata );
checkdigit( prnfile, validdata, temp1 );
break;
default: prnfile<< "Unknown record";
prnfile<< temp1 << endl;
};

}
testdata.close();
validdata.close();
prnfile.close();
return EXIT_SUCCESS;

};




The items noted above are sufficient to produce undefined behavior

-- after which all bets are off.


Also, in the future, pare down your code to the smallest possible

compilable snippet *before* you post; in doing so, you will often

find the error yourself!


HTH,

--ag

--

Artie Gold -- Austin, Texas

Oh, for the good old days of regular old SPAM.



The items noted above are sufficient to produce undefined behavior
-- after which all bets are off.

Also, in the future, pare down your code to the smallest possible
compilable snippet *before* you post; in doing so, you will often
find the error yourself!

HTH,
--ag
--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.


"muser" < CH ********** @ hotmail.com> wrote in message

news:f9**************************@posting.google.c om...
"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don’’t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is
In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don''t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is



[SNIP WAY TOO MUCH INFORMATION]


If you read the replies to your earlier post, you will see your problem.

Maybe your news server is slow - even then try to keep posts about the same

problem in the same thread; wait at least a day or two to see if your post

went through.


You frequently write past the end of an array, as in:


char code[5]; // has 5 chars, numbered _0_ to _4_

code[5] = ’’\0’’; // you are writing to char _5_ which does not exist!


Don’’t do this.


[SNIP WAY TOO MUCH INFORMATION]

If you read the replies to your earlier post, you will see your problem.
Maybe your news server is slow - even then try to keep posts about the same
problem in the same thread; wait at least a day or two to see if your post
went through.

You frequently write past the end of an array, as in:

char code[5]; // has 5 chars, numbered _0_ to _4_
code[5] = ''\0''; // you are writing to char _5_ which does not exist!

Don''t do this.


"Kevin Saff" <go********@kevin.saff.net> wrote in message news:<Hn********@news.boeing.com>...
"Kevin Saff" <go********@kevin.saff.net> wrote in message news:<Hn********@news.boeing.com>...
"muser" < CH ********** @ hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don’’t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is
In the code I supplied before this one, the cause of the problem is an
access violation error. When I run the debugger it skips into what I
can only assume is the compilers version of my code. And I don''t know
where the problem lies in the code. Can anyone run it through there
own compiler please and tell me where and what the problem is


[SNIP WAY TOO MUCH INFORMATION]

If you read the replies to your earlier post, you will see your problem.
Maybe your news server is slow - even then try to keep posts about the same
problem in the same thread; wait at least a day or two to see if your post
went through.

You frequently write past the end of an array, as in:

char code[5]; // has 5 chars, numbered _0_ to _4_
code[5] = ’’\0’’; // you are writing to char _5_ which does not exist!

Don’’t do this.


[SNIP WAY TOO MUCH INFORMATION]

If you read the replies to your earlier post, you will see your problem.
Maybe your news server is slow - even then try to keep posts about the same
problem in the same thread; wait at least a day or two to see if your post
went through.

You frequently write past the end of an array, as in:

char code[5]; // has 5 chars, numbered _0_ to _4_
code[5] = ''\0''; // you are writing to char _5_ which does not exist!

Don''t do this.




Kevin, doesn’’t my code[5] contain a NULL character and isn’’t that

housed in the fifth element?



Kevin, doesn''t my code[5] contain a NULL character and isn''t that
housed in the fifth element?


这篇关于访问冲突错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆