提示系統找不到指定文件,確定是程序的問題,求大神啊!
// 鏈表.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");
}
FILE fp = fopen( "D:\shapes.txt", "r");
--》
FILE fp = fopen( "D:\shapes.txt", "r");