c语言程序改错题技巧改错:为什么以下这段代码编译没错但运行时出错?

共有 445 人关注过本帖
标题:【求助】谁能帮我看看这段代码哪里出错了,运行不了
等 级:新手上路
帖 子:12
&&问题点数:0&&回复次数:6&&&
【求助】谁能帮我看看这段代码哪里出错了,运行不了
#include&stdio.h&
#include &conio.h&
#include &stdlib.h&
#include &string.h&
void main(void)
double x1[100],y1[100],x2[100],y2[100];
double x11,x22,y11,y22;
char *name,*
if((fp=fopen(c:&key.dxf&,&w&))==NULL)
fprintf(fp,&CANNOT OPEN FILE\n&);
fscanf(fp,&%s&,chat);
if(chat=&ENTITIES&||chat=&entities&)
&&& for(i=1;i&=2;i++)
&&& fscanf(fp,&%s&,chat);
&&& if(chat=&LINE&||chat=&line&)
&&&&&& fscanf(fp,&%s&,chat);
&&&&&& fscanf(fp,&%s&,chat);
&&&&&& fscanf(fp,&%s2d&,&n);
&&&&&& fscanf(fp,&%1f&,&x11);
&&&&&& x1[i]=x11;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y11);
&&&&&& y1[i]=y11;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&& x2[i]=x22;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&& y2[i]=y22;
&&&&&& printf(&x1=%8.2f y1=%8.2f\n&,x1[i],y1[i]);
&&&&&& printf(&x2=%8.2f y2=%8.2f\n&,x2[i],y2[i]);
&&& fscanf(fp,&%s&,chat);
&&& fscanf(fp,&%s&,chat);
&&& if(chat=&ENDSEC&||chat=&endsec&)
&&&&&&&&fscanf(fp,&%s&,chat);
&&& if(chat=&EOF&||chat=&eof&)
&&&&&&&&exit(1);
&&& fclose(fp);
搜索更多相关主题的帖子:
等 级:友情版主
威 望:66
帖 子:2166
专家分:7131
c:&key.dxf&
等 级:版主
威 望:164
帖 子:3821
专家分:20148
哪里错了不需要问别人,别人用肉眼也回答不出来,自己看编译器的编译信息
if((fp=fopen(c:&key.dxf&,&w&))==NULL)&&------ error C2065: 'c' : undeclared identifier
if(chat=&ENTITIES&||chat=&entities&)&&&------ error C2106: '=' : left operand must be l-value
fscanf(fp,&%s&,chat); ------ uninitialized local variable 'chat' used
x2[i]=x22; ------ warning C4700: uninitialized local variable 'x22' used
等 级:版主
威 望:164
帖 子:3821
专家分:20148
我觉得你最好告诉别人你想干什么,即 key.dxf 中以什么格式存储数据,你想怎么处理得出什么数据。
等 级:新手上路
帖 子:12
回复 2楼 吹水佬
第二个错误的左值不知道咋改
等 级:论坛游民
专家分:10
#include&stdio.h&
#include &conio.h&
#include &stdlib.h&
#include &string.h&
void main(void)
&&& FILE *
&&& int i,n;
&&& double x1[100],y1[100],x2[100],y2[100];
&&& double x11,x22,y11,y22;
&&& char name[100],chat[100];
&&& memset(name,0,100);
&&& memset(chat,0,100);
&&& if((fp=fopen(&c:key.dxf&,&w&))==0)
&&&&&&&&fprintf(fp,&CANNOT OPEN FILE\n&);
&&&&&&&&exit(1);
&&& fscanf(fp,&%s&,chat);
&&& if(chat == & ENTITIES&||chat == &entities&)
&&&&&&&&for(i=1;i&=2;i++)
&&&&&&&&&&&&fscanf(fp,&%s&,chat);
&&&&&&&&&&&&if(chat == &LINE&||chat == &line&)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& fscanf(fp,&%s&,chat);
&&&&&&&&&&&&&&& fscanf(fp,&%s&,chat);
&&&&&&&&&&&&&&& fscanf(fp,&%s2d&,&n);
&&&&&&&&&&&&&&& fscanf(fp,&%1f&,&x11);
&&&&&&&&&&&&&&& x1[i]=x11;
&&&&&&&&&&&&&&& fscanf(fp,&%2d&,&n);
&&&&&&&&&&&&&&& fscanf(fp,&%1f&,&y11);
&&&&&&&&&&&&&&& y1[i]=y11;
&&&&&&&&&&&&&&& fscanf(fp,&%2d&,&n);
&&&&&&&&&&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&&&&&&&&&&& x2[i]=x22;
&&&&&&&&&&&&&&& fscanf(fp,&%2d&,&n);
&&&&&&&&&&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&&&&&&&&&&& y2[i]=y22;
&&&&&&&&&&&&&&& printf(&x1=%8.2f y1=%8.2f\n&,x1[i],y1[i]);
&&&&&&&&&&&&&&& printf(&x2=%8.2f y2=%8.2f\n&,x2[i],y2[i]);
&&&&&&&&&&&&}
&&&&&&&&fscanf(fp,&%s&,chat);
&&&&&&&&fscanf(fp,&%s&,chat);
&&&&&&&&if(chat == &ENDSEC&||chat == &endsec&)
&&&&&&&&&&&&fscanf(fp,&%s&,chat);
&&&&&&&&if(chat == &EOF&||chat == &eof&)
&&&&&&&&&&&&exit(1);
&&&&&&&&fclose(fp);
等 级:黑侠
帖 子:164
专家分:579
e:\microsoft visual studio\myprojects\.cpp(15) : error C2065: 'c' : undeclared identifier
e:\microsoft visual studio\myprojects\.cpp(15) : error C2143: syntax error : missing ')' before ':'
e:\microsoft visual studio\myprojects\.cpp(15) : error C2059: syntax error : ')'
e:\microsoft visual studio\myprojects\.cpp(16) : error C2143: syntax error : missing ';' before '{'
e:\microsoft visual studio\myprojects\.cpp(21) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\.cpp(21) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\.cpp(21) : error C2440: '=' : cannot convert from 'bool' to 'char *'
&&&&&&&&Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\myprojects\.cpp(25) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\.cpp(25) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\.cpp(25) : error C2440: '=' : cannot convert from 'bool' to 'char *'
&&&&&&&&Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\myprojects\.cpp(47) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\.cpp(47) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\.cpp(47) : error C2440: '=' : cannot convert from 'bool' to 'char *'
&&&&&&&&Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\myprojects\.cpp(49) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\.cpp(49) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\.cpp(49) : error C2440: '=' : cannot convert from 'bool' to 'char *'
&&&&&&&&Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
1111.obj - 1 error(s), 0 warning(s)
编译了一下,满满的错误。。
#include&stdio.h&
#include &conio.h&
#include &stdlib.h&
#include &string.h&
void main(void)
double x1[100],y1[100],x2[100],y2[100];
double x11,x22,y11,y22;&&& --------------------&x22没有初始化。好像不知道你要做什么,暂且改成x22=0.0吧
char *name,*&&& ------------------------------------&*name这个好像没用到啊。没用到就删掉它吧。
if((fp=fopen(c:&key.dxf&,&w&))==NULL)---------& if((fp=fopen(&c:\\key.dxf&,&w&))==NULL)
fprintf(fp,&CANNOT OPEN FILE\n&);
fscanf(fp,&%s&,chat);
if(chat=&ENTITIES&||chat=&entities&)-------------&if(chat==&ENTITIES&||chat==&entities&)
&&& for(i=1;i&=2;i++)
&&& fscanf(fp,&%s&,chat);
&&& if(chat=&LINE&||chat=&line&)------------& if(chat==&LINE&||chat==&line&)
&&&&&& fscanf(fp,&%s&,chat);
&&&&&& fscanf(fp,&%s&,chat);
&&&&&& fscanf(fp,&%s2d&,&n);
&&&&&& fscanf(fp,&%1f&,&x11);
&&&&&& x1[i]=x11;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y11);
&&&&&& y1[i]=y11;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&& x2[i]=x22;
&&&&&& fscanf(fp,&%2d&,&n);
&&&&&& fscanf(fp,&%1f&,&y22);
&&&&&& y2[i]=y22;
&&&&&& printf(&x1=%8.2f y1=%8.2f\n&,x1[i],y1[i]);
&&&&&& printf(&x2=%8.2f y2=%8.2f\n&,x2[i],y2[i]);
&&& fscanf(fp,&%s&,chat);
&&& fscanf(fp,&%s&,chat);
&&& if(chat=&ENDSEC&||chat=&endsec&)---------&if(chat==&ENDSEC&||chat==&endsec&)
&&&&&&&&fscanf(fp,&%s&,chat);
&&& if(chat=&EOF&||chat=&eof&)-----------&if(chat==&EOF&||chat==&eof&)
&&&&&&&&exit(1);
&&& fclose(fp);
找到的就改了这么多,其实我也搞不懂你的代码。dxf后缀的文件是CAD格式的。。。。
版权所有,并保留所有权利。
Powered by , Processed in 0.048826 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights ReservedC语言,这段代码明明正确了为什么运行不起来?谢谢啊。 编译通过,运行却报错了,怎么回事啊_百度知道
C语言,这段代码明明正确了为什么运行不起来?谢谢啊。 编译通过,运行却报错了,怎么回事啊
jpg" />&/zhidao/pic/item/4afbfbedab64034fce58cf65a8cd3f.hiphotos.hiphotos.
为您推荐:
其他3条回答
int p1=123;%d %d&#92变量类型定义错了,p1。应该是,p2);int p2=888;printf(&;n&quot
不不,我想用的是指针啊
指针变量要使用malloc申请存储空间后才能使用的。光定义int *p1;int *p2;只是申请了存放指针的空间,并未申请存放数据的空间啊。况且这个值是地址,只能由系统分配,不能人工指定的。#include&stdio.h&#include &stdlib.h&void main(){int *p1,*p2; p1=malloc(sizeof(int)); p2=malloc(sizeof(int)); *p1=123; *p2=888; printf(&%d %d\n&,*p1,*p2);}
你理解错了😭
指针是不是不能直接输出,必须让指针指向一个变量,才能输出呢?
我理解错了?#include&stdio.h&#include &stdlib.h&int main(){int *p1,*p2;&p1=(int*)malloc(sizeof(int));&p2=(int*)malloc(sizeof(int));&*p1=123;&*p2=888;&printf(&%d %d\n&,*p1,*p2);&return 0;}这样也可以:#include&stdio.h&int main(){int a=123,b=888,*p1=a,*p2=b;&printf(&%d %d\n&,*p1,*p2);&return 0;}
不要给指针变量直接赋值啊
指针不能直接输出,必须让指针指向一个变量名,才能正常输出指针的值,是吗?
软件再装下
c语言的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁23:01 提问
大家好,下面这段程序在vc6.0中编译时没错误,但却运行不起来。麻烦帮看一下
int main()
int shu,shang,i,
int a[16]={0};
printf("shu ru yi ge shu shi jin zhi\n ");
scanf("%d",shu);
yushu=shu%2;
shang=shu/2;
for(i=15;i&=0;i--)
printf("%d",a[i]);
if(i%4==0)
printf(" ");
按赞数排序
头文件怎么没有?
还有输入的时候应该是 scanf("%d",&shu)才对
scanf("%d",shu);有问题,应该是scanf("%d",&shu);
楼上正解,很初级的错误啊。
120关注|133收录
422关注|231收录
368关注|848收录
其他相似问题求教C语言大神,这段代码有什么问题,能编译但不能运行是为什么?_百度知道
求教C语言大神,这段代码有什么问题,能编译但不能运行是为什么?
s); printf(&='A' )) y++!=&#39,k=0;='z' return 0;&&c&n& ';n&quot,q);=' printf(&='其他字符个数为%d个&#92.h&gt,q=0;='数字个数为%d个\
else if(c&
while((c=getchar());&&c&; } printf(& printf(&quot,k);\9'0';) k++;英文字母个数为%d个\) s++;int mian(){ int y=0;Z'n&;) {
else q++,s=0;=')||(c&n'空格个数个数为%d个\
else if(c=='a'n&&&c&lt,y)#include&stdio
提问者采纳
你开头就不对……是main不是mian
提问者评价
啊!!!我真是sb了,多谢多谢
其他类似问题
为您推荐:
其他1条回答
}else if(条件2){
语句2;}else if(条件3){
语句3;}else{
其他语句你的if
else语句写的有问题吧,大括号呢,标准的应该是这样写吧if(条件1){
语句1,如果能帮助到你;}改了后试一下
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁查看: 1880|回复: 5
C语言--高手看看这代码,编译没有错误--运行时出错,求解
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 91 天[LV.6]签到狂人I
当前用户组为 凤毛麟角 [信息未更新]当前积分为 337, 升到下一级还需要 663 点。
# include &stdio.h&
void fun(double a, double b, double *p1, double *p2)
& & & & *p1 = a +
& & & & *p2 = a -
int main()
& & & & double x,
& & & & printf(&请输入:&);
& & & & scanf(&%f %f&, x, y);
& & & & fun(x, y, &x, &y);
& & & & printf(&和为x = %f\n&, x);
& & & & printf(&查为y = %f\n&, y);
& & & & return 0;
--编译没有错误--运行时出错,是怎么回事,这代码有错吗?
BcWhy版权声明1、本主题所有言论和图片纯属个人意见,与本论坛立场无关
2、本主题由该帖子作者发表,该帖子作者与本站享有帖子相关版权
3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和本站的同意
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、本站管理员和版主有权不事先通知发贴者而删除本文
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 1748 天[LV.Master]论坛元老
# include &stdio.h&
void fun(double a, double b, double *p1, double *p2)
{
& & & & *p1 = a +
& & & & *p2 = a -
& & & &
int main()
{
& & & & double x,
& & & & printf(&请输入:&);
& & & & scanf(&%lf %lf&, &x, &y);
& & & & fun(x, y, &x, &y);
& & & & printf(&和为a = %f\n&, x);
& & & & printf(&查为b = %f\n&, y);
& & & &
& & & & return 0;
}
复制代码
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 1748 天[LV.Master]论坛元老
两个问题。一个,输入double类型要用 %lf 再一个。。输入的时候要加 & 符号
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 91 天[LV.6]签到狂人I
当前用户组为 凤毛麟角 [信息未更新]当前积分为 337, 升到下一级还需要 663 点。
夜影 发表于
喔,忘了,谢谢
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 3 天[LV.2]偶尔看看
当前用户组为 锋芒初露当前积分为 12, 升到下一级还需要 288 点。
16 17 行 %f 按照格式匹配 也应是%lf&&不过 都是%f同样没有问题&&我记得 %f 默认是按double型处理的。
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
签到天数: 390 天[LV.9]以坛为家II
看到一个问题。。。已经被解决了。。。
BcWhy推荐 /1
在手机上就能与bcwhy的朋友交流,手机也能学编程~
快来下载安装:
Powered by

我要回帖

更多关于 c语言改错 的文章

 

随机推荐