提示系统找不到指定文件,确定是程序的问题,求大神啊!
// 链表.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");
}