可能的段错误 [英] possible seg fault
问题描述
以下程序在Microsoft Visual C ++
6.0编译器上成功编译但是当我执行它时..遇到一个未知的
错误。可能是因为一个段错误..
#include< string.h>
#include< iostream.h>
int main(int argc,char ** argv){
int i;
int len;
char * addressLine [8 ];
addressLine [1] =" String1";
addressLine [2] =" String2";
for(i = 1; i< = 8; i ++){
len = strlen(addressLine [i]);
if(len> = 1){
cout<< 地址: << addressLine [i];
cout<< " \ n";
}
}
返回(0);
}
但是当我在没有循环的情况下使用以下内容时..
cout<< 地址: << addressLine [1];
它工作正常...
请帮助!...
The following program compiles successfully on a Microsoft Visual C++
6.0 compiler but when I execute it..it encounters an unknown
error..may be a because of a seg fault..
#include <string.h>
#include <iostream.h>
int main(int argc, char **argv){
int i;
int len;
char *addressLine[8];
addressLine[1] = "String1";
addressLine[2] = "String2";
for(i = 1; i <= 8; i++){
len = strlen(addressLine[i]);
if (len >= 1){
cout << "Address: " << addressLine[i];
cout << "\n";
}
}
return (0);
}
but when I just use the following without the loop..
cout << "Address: " << addressLine[1];
it just works fine...
Please help!...
推荐答案
jh*******@fastermail.com aécrit:
jh*******@fastermail.com a écrit :
以下程序在Microsoft Visual C ++
6.0编译器上成功编译,但是当我执行它时..遇到一个未知的
错误。可能是因为一个段错误...
#include< string.h>
#include< iostream.h>
int main(int argc,char ** argv){
int i;
int len;
char * addressLine [8];
addressLine [1] =" String1";
addressLine [2] =" String2";
for(i = 1; i< = 8; i ++){
len = strlen (addressLine [i]);
if(len> = 1){
cout<< 地址: << addressLine [i];
cout<< " \ n";
}
}
返回(0);
}
但是当我在没有循环的情况下使用以下内容时..
cout<< 地址: << addressLine [1];
它工作正常...
请帮助!...
The following program compiles successfully on a Microsoft Visual C++
6.0 compiler but when I execute it..it encounters an unknown
error..may be a because of a seg fault..
#include <string.h>
#include <iostream.h>
int main(int argc, char **argv){
int i;
int len;
char *addressLine[8];
addressLine[1] = "String1";
addressLine[2] = "String2";
for(i = 1; i <= 8; i++){
len = strlen(addressLine[i]);
if (len >= 1){
cout << "Address: " << addressLine[i];
cout << "\n";
}
}
return (0);
}
but when I just use the following without the loop..
cout << "Address: " << addressLine[1];
it just works fine...
Please help!...
您没有初始化addressLine数组的3..8条目......他们的
内容是纯垃圾...
You did not initialize entries 3..8 of the addressLine array... their
content is pure garbage...
9月16日下午5:27,Laurent DAM MENTEN"
< laurent.men ... @ teledisnet.bewrote:
On Sep 16, 5:27 pm, "Laurent D.A.M. MENTEN"
<laurent.men...@teledisnet.bewrote:
jhagen ... @ fastermail.comaécrit:
jhagen...@fastermail.com a écrit :
以下程序在Microsoft Visual C ++
6.0编译器上成功编译,但是当我执行它时。 。遇到一个未知的
错误。可能是因为一个段错误..
The following program compiles successfully on a Microsoft Visual C++
6.0 compiler but when I execute it..it encounters an unknown
error..may be a because of a seg fault..
#include< string.h>
#include< iostream.h>
#include <string.h>
#include <iostream.h>
int main(int argc,char ** argv){
int i;
int len;
char * addressLine [8];
int main(int argc, char **argv){
int i;
int len;
char *addressLine[8];
addressLine [1] =" String1";
addressLine [2] =" String2" ;;
addressLine[1] = "String1";
addressLine[2] = "String2";
for(i = 1; i< = 8; i ++){
len = strlen(addressLine [i ]);
if(len> = 1){
cout<< 地址: << addressLine [i];
cout<< " \ n";
}
}
返回(0);
}
for(i = 1; i <= 8; i++){
len = strlen(addressLine[i]);
if (len >= 1){
cout << "Address: " << addressLine[i];
cout << "\n";
}
}
return (0);
}
但是当我在没有循环时使用以下内容时..
but when I just use the following without the loop..
cout << 地址: <<地址第一行];
cout << "Address: " << addressLine[1];
它运作正常...
it just works fine...
请帮忙! ...
Please help!...
您没有初始化addressLine数组的条目3..8 ......他们的
内容是纯垃圾... .-隐藏引用的文字 -
- 显示引用的文字 -
You did not initialize entries 3..8 of the addressLine array... their
content is pure garbage...- Hide quoted text -
- Show quoted text -
谢谢!对于你的回复..我需要在数组中只使用2个条目...如何
我通过同时处理错误进行迭代和打印..我试过了
使用
if(!addressLine [i]){
//打印价值..
}
但同样的问题..
Thanks! for ur reply..I need to use only 2 entries in the array...How
do I iterate and print by handling the error at the same time..I tried
to use
if(!addressLine[i]){
//Print value..
}
but same problem..
Laurent DAM MENTEN写道:
Laurent D.A.M. MENTEN wrote:
jh ******* @ fastermail.com aécrit:
jh*******@fastermail.com a écrit :
>以下程序在Microsoft Visual C ++
6.0编译器上成功编译但是当我执行它时遇到一个未知的
错误......可能是因为一个段错误。
#include< string.h>
#include< iostream.h>
int main(int argc,char ** argv){
int i;
int len;
char * addressLine [8];
addressLine [ 1] =" String1";
addressLine [2] =" String2";
for(i = 1; i< = 8; i ++){
len = strlen(addressLine [i]);
if(len> = 1){
cout<< 地址: << addressLine [i];
cout<< " \ n";
}
}
返回(0);
}
但是当我在没有循环时使用以下内容时。 。
cout<< 地址: << addressLine [1];
它工作正常......
请帮助!...
>The following program compiles successfully on a Microsoft Visual C++
6.0 compiler but when I execute it..it encounters an unknown
error..may be a because of a seg fault..
#include <string.h>
#include <iostream.h>
int main(int argc, char **argv){
int i;
int len;
char *addressLine[8];
addressLine[1] = "String1";
addressLine[2] = "String2";
for(i = 1; i <= 8; i++){
len = strlen(addressLine[i]);
if (len >= 1){
cout << "Address: " << addressLine[i];
cout << "\n";
}
}
return (0);
}
but when I just use the following without the loop..
cout << "Address: " << addressLine[1];
it just works fine...
Please help!...
你没有初始化addressLine数组的3..8条目......他们的
内容是纯垃圾...
You did not initialize entries 3..8 of the addressLine array... their
content is pure garbage...
我的理解是[8]的数组会有来自
0..7的有效指示,并且在c ++数组指示中从零开始,具有n
元素的数组将是有来自0..n-1的指标。所以我认为他没有初始化
元素零和元素3..7。
再次检查循环。
>
您可能还想查看std :: string。
LR
My understanding is that an array of [8] would have valid indicies from
0..7, and that in c++ array indicies start at zero, an array with n
elements will have indicies from 0..n-1. So I think he didn''t initialize
element zero and elements 3..7.
Check the loop again.
You may also want to look at std::string.
LR
这篇关于可能的段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!