奇怪的lcc-win32行为 [英] Weird lcc-win32 behaviour

查看:105
本文介绍了奇怪的lcc-win32行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我可以通过一个简单的程序在freebsd下编译以下程序:

gcc prog1.c -o prog1

它运行顺利,我遇到了烦人的问题在windows xp pro下lcc-win32

的问题。事实上,在wedit下,我可以顺利编译

程序,但是当我尝试执行它时,它以异常终止结束

并且弹出窗口抱怨:


lcc运行时

例外0xc0000005

段违规

地址0x73d115ce


如果您认为削减计划的许多行

并在行之后立即停止执行

fscanf(fp," %d%d",& R,& C);


lcc-win32对相同的例外窒息。


请帮助

Vittorio


对于想要去的人来说,这是prog1.c


/ * prog1。 c * /

/ * PROGRAMMA 1

Il file matrice.txt(presente nella cartella esame)contiene alcuni dati

cosi''organizzati:

RC

a0,0 a0,1 a0,2 a0,3 ... a0,C-1

a1,0 a1, 1 a1,2 a1,3 ... a1,C-1

a2,0 a2,1 a 2,2 a2,3 ... a2,C-1

.......

aR-1,0 aR-1,1 ...... ......... aR-1,C-1

dove R e C indicano il numero di righe e di colonne della matrice che segue,

e'''elemento generico ai,j e''un reale。

Si chiede di scrivere un programma che:


- legga questo file, trasferendo i valori in una matrice di reali(float)

allocata dinamicamente

- allochi una seconda matrice di reali delle stesse dimensioni

- ponga nell ''elemento i ,, j della seconda matrice la somma di tutta la riga i

e di tutta la colonna j della prima matrice

- scriva la matrice risultante nel file destinazione。 txt,在modalita''

testo,con una sola cifra decimale per ogni elemento


Al termine chiudere i file e liberare la memoria。 * /

#include< stdio.h>

#include< stdlib.h>

void main(void){

int i,j;

int R,C;


/ * Leggo matrice.txt,trasferendo i valori in una matrice m1 di reali

allocata dinamicamente * /

FILE * fp;

fp = fopen(" matrice.txt"," r") ;

fscanf(fp,"%d%d",& R& C);


float ** m1;

m1 =(float **)malloc(sizeof(float *)* R);

for(i = 0; i< R; i ++)

m1 [i] =(float *)malloc(sizeof(float)* C);


for(i = 0; i< R; i ++)

for(j = 0; j< C; j ++)

fscanf(fp,"%f",& m1 [i] [j]);

for(i = 0; i< R; i ++){

for(j = 0; j< C; j ++)

printf("%6.1f" ,m1 [i] [j]);

printf(" \ n");

}

/ * Alloco una seconda matrice di reali delle stesse dimensioni * /

float ** m2;

m2 =(float **)malloc(sizeof(float *)* R);

for(i = 0; i< R; i ++)

m2 [i] =(float *)malloc(sizeof(float)* C);

/ * Pongo nell''elemento i,j della seconda matrice la somma di tutta la riga i

e di tutta la colonna j della prima matrice * /


/ * r,ec sono 2 vettori in cui pongo la somma dellle righe e colonne * /

float * r,

* c;

r = (float *)malloc(sizeof(float)* R);

c =(float *)malloc(sizeof(float)* C);


for (i = 0; i< R; i ++){

r [i] = 0;

for(j = 0; j< C; j ++)

r [i] + = m1 [i] [j];

printf(" r%8.1f \ n",r [i]);

}


for(j = 0; j< C; j ++){

c [j] = 0;

for(i = 0; i< R; i ++)

c [j] + = m1 [i] [j];

printf(" c%8.1f \\ \\ n,c [j]);

}


for(i = 0; i< R; i ++)

for(j = 0; j< C; j ++)

m2 [i] [j] = r [i] + c [j];

FILE * fo ;

fo = fopen(" destinazione.txt"," w");

for(i = 0; i< R; i ++){

for(j = 0; j< C; j ++)

fprintf( fo,%6.1f,m2 [i] [j]);

fprintf(fo," \ n");

}

/ * Chiudo我提交e libero la memoria * /

fclose(fp);

fclose(fo);

for(i = 0; i< R; i ++)

free(m1 [i]);

free(m2 [i]);

免费(r);

免费(c);

免费(m1);

免费(m2);

}


解决方案

vittorio< vi **** @ SPAM-tin 。它>写在

news:43 *********************** @ reader3.news.tin.it:
< blockquote class =post_quotes>虽然我可以通过一个简单的程序在freebsd下编译程序:
gcc prog1.c -o prog1
并且它运行顺利,我遇到了烦人的问题windows xp pro下的lcc-win32。实际上,在wedit下,我可以顺利地编译程序,但是当我尝试执行它时,它会以异常终止结束。并且弹出窗口抱怨:

lcc运行时
异常0xc0000005
段违规
地址0x73d115ce




< code snipped>


请正确且一致地缩进,并使用一些额外的空格。


我看到没有错误检查fopen ,fscanf和malloc电话。


有很多非常丑陋的演员出现在周围。


我会先看看fscanf返回什么,以及R和C是否包含你认为他们应该的



思南


-

A. Sinan Unur< 1u ** @ llenroc.ude.invalid>

(反转每个组件并删除.invalid for email address)


一种。 Sinan Unur写道:

vittorio< vi **** @ SPAM-tin.it>在
新闻中写道:43 *********************** @ reader3.news.tin.it:

虽然我可以通过一个简单的程序在freebsd下编译程序:
gcc prog1.c -o prog1
并且它运行顺利,我遇到了烦人的问题
lcc- windows xp pro下的win32。实际上,在wedit下,我可以顺利地编译程序,但是当我尝试执行它时,它会以异常终止结束。并且弹出窗口抱怨:

lcc运行时
异常0xc0000005
段违规
地址0x73d115ce



<代码剪切> ;

请正确一致地缩进,并使用一些额外的空格。

我看不到fopen,fscanf和malloc调用的错误检查。
<有很多非常丑陋的演员出现在周围。

我首先会看到fscanf会返回什么,以及R和C是否包含你认为应该的东西。

思南



思南,

正如我所说甚至缩短了该项目的线路

" fscanf( FP,"%d%d",&安培; R,和C);" lcc-win32编译顺利但不执行

它给出了相同的lcc运行时异常。因此,无法检查R $ />
& C就像。虽然 - 我在freebsd下重复没有问题!


这是一个不切实际的问题:你究竟用什么来表达... ...

相当一些丑陋的演员们漂浮在周围......:什么是非常丑陋的

演员表?


Ciao

Vittorio


vittorio< vi **** @ SPAM-tin.it>写在

news:43 ********************** @ reader4.news.tin.it:

A. Sinan Unur写道:

vittorio< vi **** @ SPAM-tin.it>在
新闻中写道:43 *********************** @ reader3.news.tin.it:

虽然我可以通过一个简单的程序在freebsd下编译程序:
gcc prog1.c -o prog1
并且它运行顺利,我遇到了烦人的问题
lcc- windows xp pro下的win32。实际上,在wedit下,我可以顺利地编译程序,但是当我尝试执行它时,它会以异常终止结束。并且弹出窗口抱怨:

lcc运行时
异常0xc0000005
段违规
地址0x73d115ce
<代码剪切>
请正确一致地缩进,并使用一些额外的空白。

我看不到fopen,fscanf和malloc调用的错误检查。

那里很多丑陋的演员都漂浮在周围。

我首先会看到fscanf会返回什么,以及R和C是否包含你认为应该的东西。
思南


思南,
正如我所说的那样,甚至缩短了节目中的节目
fscanf(fp,%d%d,& R,& C);" lcc-win32编译顺利,但不要执行它给出相同的lcc运行时异常。




那么请提供我们可以编译的最短代码通过

只需复制和粘贴,以及样本输入。

这是一个不太常见的问题:你用什么来表达
...那里漂浮在周围的是一些非常丑陋的演员......:什么是非常丑陋的演员?




以下是一个丑陋的演员:


#include< stdlib.h>


....


float * * m1;

m1 =(float **)malloc(sizeof(float *)* R);


演员表(浮动**)不是需要。它会使代码混乱,如果你曾经忘记包含stdlib.h,那么你就不会收到警告。


从我的猜测来看,上面推荐的替代品是:


浮动** m1 = malloc(R * sizeof(* m1));


这是更不容易出错,如果你改变了m1的类型,你只需要在一个地方做到这一点。 (顺便说一句,你为什么不用?

双打?)


思南

-

A. Sinan Unur< 1u ** @ llenroc.ude.invalid>

(反转每个组件并删除.invalid的电子邮件地址)


关于WWW的comp.lang.perl.misc指南:
http://mail.augustmail.com/~tadmc/cl...uidelines.html


While I can compile the program below under freebsd via a simple:
gcc prog1.c -o prog1
and it runs smoothly, I''m experiencing annoying problems with lcc-win32
under windows xp pro. In fact, under wedit, I can smoothly compile the
program but when I try to execute it it ends with an "abnormal termination"
and a popup complains that:

lcc runtime
Exception 0xc0000005
segment violation
address 0x73d115ce

The weirdness is greater if you think that cutting many lines of the program
and stopping the execution imediatedly after the line
fscanf(fp,"%d%d",&R,&C);

lcc-win32 chokes on the same exception.

Please help
Vittorio

For thoes who wants to have a go here is prog1.c

/* prog1.c */
/* PROGRAMMA 1
Il file matrice.txt (presente nella cartella esame) contiene alcuni dati
cosi'' organizzati:
R C
a0,0 a0,1 a0,2 a0,3 ... a0,C-1
a1,0 a1,1 a1,2 a1,3 ... a1,C-1
a2,0 a2,1 a2,2 a2,3 ... a2,C-1
.......
aR-1,0 aR-1,1............ aR-1,C-1

dove R e C indicano il numero di righe e di colonne della matrice che segue,
e l''elemento generico ai,j e'' un reale.
Si chiede di scrivere un programma che:

- legga questo file, trasferendo i valori in una matrice di reali (float)
allocata dinamicamente
- allochi una seconda matrice di reali delle stesse dimensioni
- ponga nell''elemento i,,j della seconda matrice la somma di tutta la riga i
e di tutta la colonna j della prima matrice
- scriva la matrice risultante nel file destinazione.txt, in modalita''
testo, con una sola cifra decimale per ogni elemento

Al termine chiudere i file e liberare la memoria. */
#include <stdio.h>
#include <stdlib.h>
void main(void){
int i,j;
int R,C;

/*Leggo matrice.txt,trasferendo i valori in una matrice m1 di reali
allocata dinamicamente*/
FILE *fp;
fp=fopen("matrice.txt","r");
fscanf(fp,"%d%d",&R,&C);

float **m1;
m1=(float**)malloc(sizeof(float*)*R);
for(i=0;i<R;i++)
m1[i]=(float*)malloc(sizeof(float)*C);

for(i=0;i<R;i++)
for(j=0;j<C;j++)
fscanf(fp,"%f",&m1[i][j]);
for(i=0;i<R;i++){
for(j=0;j<C;j++)
printf("%6.1f",m1[i][j]);
printf("\n");
}
/*Alloco una seconda matrice di reali delle stesse dimensioni*/
float **m2;
m2=(float**)malloc(sizeof(float*)*R);
for(i=0;i<R;i++)
m2[i]=(float*)malloc(sizeof(float)*C);
/*Pongo nell''elemento i,j della seconda matrice la somma di tutta la riga i
e di tutta la colonna j della prima matrice*/

/*r, e c sono 2 vettori in cui pongo la somma dellle righe e colonne */
float *r,
*c;
r=(float*)malloc(sizeof(float)*R);
c=(float*)malloc(sizeof(float)*C);

for(i=0;i<R;i++){
r[i]=0;
for(j=0;j<C;j++)
r[i]+=m1[i][j];
printf("r %8.1f \n", r[i]);
}

for(j=0;j<C;j++){
c[j]=0;
for(i=0;i<R;i++)
c[j]+=m1[i][j];
printf("c %8.1f \n", c[j]);
}

for(i=0;i<R;i++)
for(j=0;j<C;j++)
m2[i][j]=r[i]+c[j];
FILE *fo;
fo=fopen("destinazione.txt","w");

for(i=0;i<R;i++){
for(j=0;j<C;j++)
fprintf(fo,"%6.1f",m2[i][j]);
fprintf(fo,"\n");
}
/*Chiudo i file e libero la memoria*/
fclose(fp);
fclose(fo);
for(i=0;i<R;i++)
free(m1[i]);
free(m2[i]);
free(r);
free(c);
free(m1);
free(m2);
}



解决方案

vittorio <vi****@SPAM-tin.it> wrote in
news:43***********************@reader3.news.tin.it :

While I can compile the program below under freebsd via a simple:
gcc prog1.c -o prog1
and it runs smoothly, I''m experiencing annoying problems with
lcc-win32 under windows xp pro. In fact, under wedit, I can smoothly
compile the program but when I try to execute it it ends with an
"abnormal termination" and a popup complains that:

lcc runtime
Exception 0xc0000005
segment violation
address 0x73d115ce



<code snipped>

Please indent properly and consistently, and use some extra whitespace.

I see no error-checking for the fopen, fscanf, and malloc calls.

There are quite a few extra-ugly casts floating around.

I would first see what fscanf returns, and whether R and C contain what
you thought they should.

Sinan

--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)


A. Sinan Unur wrote:

vittorio <vi****@SPAM-tin.it> wrote in
news:43***********************@reader3.news.tin.it :

While I can compile the program below under freebsd via a simple:
gcc prog1.c -o prog1
and it runs smoothly, I''m experiencing annoying problems with
lcc-win32 under windows xp pro. In fact, under wedit, I can smoothly
compile the program but when I try to execute it it ends with an
"abnormal termination" and a popup complains that:

lcc runtime
Exception 0xc0000005
segment violation
address 0x73d115ce



<code snipped>

Please indent properly and consistently, and use some extra whitespace.

I see no error-checking for the fopen, fscanf, and malloc calls.

There are quite a few extra-ugly casts floating around.

I would first see what fscanf returns, and whether R and C contain what
you thought they should.

Sinan


Sinan,
as I said even shortening the program at the line
"fscanf(fp,"%d%d",&R,&C);" lcc-win32 compiles smoothly but don''t exewcute
it giving the same lcc runtime exception. Therefore, No way to check what R
& C are like. While - I repeat under freebsd no problems!

By the way a lessical question: what do you exactly mean with "...There are
quite a few extra-ugly casts floating around...": what are extra-ugly
casts?

Ciao
Vittorio


vittorio <vi****@SPAM-tin.it> wrote in
news:43**********************@reader4.news.tin.it:

A. Sinan Unur wrote:

vittorio <vi****@SPAM-tin.it> wrote in
news:43***********************@reader3.news.tin.it :

While I can compile the program below under freebsd via a simple:
gcc prog1.c -o prog1
and it runs smoothly, I''m experiencing annoying problems with
lcc-win32 under windows xp pro. In fact, under wedit, I can smoothly
compile the program but when I try to execute it it ends with an
"abnormal termination" and a popup complains that:

lcc runtime
Exception 0xc0000005
segment violation
address 0x73d115ce
<code snipped>

Please indent properly and consistently, and use some extra
whitespace.

I see no error-checking for the fopen, fscanf, and malloc calls.

There are quite a few extra-ugly casts floating around.

I would first see what fscanf returns, and whether R and C contain
what you thought they should.

Sinan


Sinan,
as I said even shortening the program at the line
"fscanf(fp,"%d%d",&R,&C);" lcc-win32 compiles smoothly but don''t
exewcute it giving the same lcc runtime exception.



Then please provide the shortest possible code that we can compile by
just copying and pasting, along with sample input.
By the way a lessical question: what do you exactly mean with
"...There are quite a few extra-ugly casts floating around...": what
are extra-ugly casts?



The following is an ugly cast:

#include <stdlib.h>

....

float **m1;
m1=(float**)malloc(sizeof(float*)*R);

The cast (float**) is not needed. It clutters the code, and if you ever
did forget to include stdlib.h, you would not get a warning.

From what I can surmise, the recommended replacement for the above is:

float **m1 = malloc(R * sizeof(*m1));

which is far less error prone, and if you ever changed the type of m1,
you only need to do it in one place. (BTW, why aren''t you using
doubles?)

Sinan
--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html


这篇关于奇怪的lcc-win32行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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