| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1354 人关注过本帖
标题:【求助】谁能帮我看看这段代码哪里出错了,运行不了
只看楼主 加入收藏
youxin123
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2016-5-9
结帖率:0
收藏
 问题点数:0 回复次数:6 
【求助】谁能帮我看看这段代码哪里出错了,运行不了
#include<stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>
void main(void)
{
FILE *fp;
int i,n;
double x1[100],y1[100],x2[100],y2[100];
double x11,x22,y11,y22;
char *name,*chat;
if((fp=fopen(c:"key.dxf","w"))==NULL)
{
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);
 }
搜索更多相关主题的帖子: include double 
2016-06-07 15:26
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10543
专家分:42958
注 册:2014-5-20
收藏
得分:0 
c:"key.dxf"
2016-06-07 15:31
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
哪里错了不需要问别人,别人用肉眼也回答不出来,自己看编译器的编译信息
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
2016-06-07 15:33
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
我觉得你最好告诉别人你想干什么,即 key.dxf 中以什么格式存储数据,你想怎么处理得出什么数据。
2016-06-07 15:37
youxin123
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2016-5-9
收藏
得分:0 
回复 2楼 吹水佬
第二个错误的左值不知道咋改
2016-06-07 15:45
zhangyoung
Rank: 2
等 级:论坛游民
威 望:1
帖 子:3
专家分:10
注 册:2016-6-7
收藏
得分:0 
#include<stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>
void main(void)
{
    FILE *fp;
    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);
}
2016-06-07 16:34
lanke711
Rank: 9Rank: 9Rank: 9
来 自:流浪在天国之路
等 级:蜘蛛侠
威 望:7
帖 子:317
专家分:1437
注 册:2015-7-16
收藏
得分:0 
e:\microsoft visual studio\myprojects\1314\1111.cpp(15) : error C2065: 'c' : undeclared identifier
e:\microsoft visual studio\myprojects\1314\1111.cpp(15) : error C2143: syntax error : missing ')' before ':'
e:\microsoft visual studio\myprojects\1314\1111.cpp(15) : error C2059: syntax error : ')'
e:\microsoft visual studio\myprojects\1314\1111.cpp(16) : error C2143: syntax error : missing ';' before '{'
e:\microsoft visual studio\myprojects\1314\1111.cpp(21) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\1314\1111.cpp(21) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\1314\1111.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\1314\1111.cpp(25) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\1314\1111.cpp(25) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\1314\1111.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\1314\1111.cpp(47) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\1314\1111.cpp(47) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\1314\1111.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\1314\1111.cpp(49) : warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
e:\microsoft visual studio\myprojects\1314\1111.cpp(49) : error C2106: '=' : left operand must be l-value
e:\microsoft visual studio\myprojects\1314\1111.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)
{
FILE *fp;
int i,n;
double x1[100],y1[100],x2[100],y2[100];
double x11,x22,y11,y22;    -------------------->x22没有初始化。好像不知道你要做什么,暂且改成x22=0.0吧
char *name,*chat;    ------------------------------------>*name这个好像没用到啊。没用到就删掉它吧。
if((fp=fopen(c:"key.dxf","w"))==NULL)---------> if((fp=fopen("c:\\key.dxf","w"))==NULL)
{
fprintf(fp,"CANNOT OPEN FILE\n");
exit(1);
}
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格式的。。。。

普通人之所以普通,是因为他们普遍有一个通病,那就是认为自己永远普通。
千夫所指,我亦坚持。就算被所有人误解,我也照样守护这一切。
我们总是觉得,这些灵魂的表情,傲慢自大,目中无人,其实,真正目中无人的是我们。它们傲慢的不过是表情,而我们傲慢的却是行为!
记得,是为了忘记!
只要想着有那么一天,我就能忍受现在的每一天!
灾难并不可怕,可怕的是心中没有了希望。
你以为我在天堂,其实我正在路上。
当你觉得自己走不到终点的时候,请不要放弃。或许你的对手也是这种感觉。
2016-06-07 20:38
快速回复:【求助】谁能帮我看看这段代码哪里出错了,运行不了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018391 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved