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

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 09:42
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器