程序不太行 2013-09-28 07:01 采纳率: 100%
浏览 4185
已采纳

C++编程问题:系统找不到指定文件(确定是程序的问题)

提示系统找不到指定文件,确定是程序的问题,求大神啊!

// 链表.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "windows.h"
#include "conio.h"

//创建POINT的同义
typedef POINT datatype;

typedef struct node
{
datatype data;
struct node *next;
}nodetype;

//声明数据操作
nodetype *creat(nodetype *L);
void InsertElem(nodetype *L,int i,int x,int y);
void DeleteElem(nodetype *L,int i);
void Clear(nodetype *L);
nodetype *GetElem(nodetype *L,int i);
int Length( nodetype *L );

//声明画布的操作
void DrawLine(nodetype *L,HDC hdc);
void clearWindow(HWND hwnd);

int main(int argc, _TCHAR* argv[])
{

HWND hwnd = GetConsoleWindow();
HDC hdc = GetDC( hwnd );
::SelectObject( hdc, GetStockObject( DC_PEN ));
::SetDCPenColor( hdc, RGB( 0,0,255 ));

nodetype *list;
Clear(list);
nodetype *creat(list);

DrawLine( list, hdc);
getchar();
clearWindow(hwnd);
getchar();
DrawLine( list, hdc);

int i,x,y;
getchar();
printf("请输入要插入点的id,点坐标:");
scanf("\n%d\t%d\t%d",&i,&x,&y);
InsertElem( list,i ,x,y);
getchar();
clearWindow(hwnd);
getchar();
DrawLine( list, hdc);

getchar();
printf("请输入要删除的点的id:");
scanf("\n%d",&i);
DeleteElem(list, i );
getchar();
clearWindow(hwnd);
getchar();
DrawLine( list, hdc);

return 0;
}

void clearWindow( HWND hwnd )
{
InvalidateRect( hwnd, NULL, true );
UpdateWindow( hwnd );
system("cls");
}
nodetype creat(nodetype *L)
{
FILE
fp = fopen( "D:\shapes.txt", "r");
if( fp)
{
char line[200];
fgets( line,200, fp);
//printf( "%s", line);

    int shapeCount;
    fscanf( fp, "%d\n",&shapeCount);
    //printf( "shapeCount = %d \n", shapeCount );
    //getch();

    int shapeType, id , vertexCount;

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

        fscanf( fp, "%d,%d,%d\n",&shapeType, &id , &vertexCount);
        //printf( "shapeType = %d ,id = %d, vertexCount = %d \n", shapeType,id, vertexCount );
        //getch();

nodetype *s,*t; 
nodetype *h=(nodetype*)malloc(sizeof(nodetype));
for(int i=0;i<shapeCount;++i)
{
    nodetype* s=(nodetype*)malloc(sizeof(nodetype));
    fscanf( fp, "%d,%d\n",s->data.x,s->data.y);
    s->next=NULL;t->next=s;t=s;
}return h;
    }

}

void DrawLine(nodetype *L,HDC hdc)
{
int x,y;
char label[20];
POINT pt;
nodetype *p;
p=GetElem(L,0);
p->data.x=pt.x;
p->data.y=pt.y;
sprintf( label, "%d,%d", pt.x, pt.y );
TextOutA( hdc, pt.x,pt.y, label, strlen( label ));
//printf( "%d,%d\n" , pt.x, pt.y );

MoveToEx( hdc,pt.x, pt.y,0 );
for ( int i = 2; i <= Length( L ) ; ++i )
{
    p=GetElem(L, i );
    p->data.x=pt.x;
    p->data.y=pt.y;
    LineTo( hdc, pt.x,pt.y );
    sprintf( label, "%d,%d", pt.x, pt.y );
    TextOutA( hdc, pt.x,pt.y, label, strlen( label ));
    //printf( "%d,%d\n" , pt.x, pt.y );
}

}

void InsertElem(nodetype *L,int i,int x,int y)
{

nodetype *e,*p,*q;

p=GetElem(L, i-1);
q=GetElem(L, i);
e->data.x=x;
e->data.y=y;;
e->next=q;p->next=e;
}

nodetype *GetElem(nodetype *L,int i)
{nodetype *p=L;
int j=0;

while((p->next!=NULL)&&(j {
p=p->next;j++;
}
if(i==j)return p;
else return NULL;
}

void DeleteElem(nodetype *L,int i)
{
nodetype *p,*r;

p=GetElem(L, i-1);
if( (p!=NULL) && (p->next!=NULL))
{
nodetype * r = p->next; p->next = r->next; free(r);
}
else printf("error\n");
}

展开全部

  • 写回答

2条回答 默认 最新

  • Eleven 2015-01-04 01:42
    关注

    FILE fp = fopen( "D:\shapes.txt", "r");
    --》
    FILE fp = fopen( "D:\shapes.txt", "r");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 利用3支股票数据估计其均值和方差的95%置信区间。
  • ¥15 微信小程序运行一项功能时,弹出未知错误弹框,检查代码没有问题
  • ¥15 ATAC测序生成self-pseudo replicates之前是否要进行去线粒体reads
  • ¥15 python模糊字匹配函数问题
  • ¥20 谁刷目标页面的uv记录器上数据,数据只记录跳转的数值
  • ¥30 数据库软件的安装方法
  • ¥15 一道以太网数据传输题
  • ¥15 python 下载群辉文件
  • ¥50 代码还没怎么运行但是需要代码功能调用数据
  • ¥15 vue请求不到数据,返回状态200,数据为html