473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

高手求救 fatal error C1004: unexpected end of file found??? why?

//迷宫问题
#include<stdio.h>
#include<malloc.h>
#define sqstack S
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
struct zuobiao{
int i;
int j;
};

struct SElemType{
int type;
int di;
struct zuobiao seat;};
struct sqstack{
struct SElemType *base;
struct SElemType *top;
int stacksize;}s;

struct SElemType e,curpose;
struct SElemType *InitStack(S &s){
s.base=(struct SElemType*)malloc(STACK_INIT_SIZE*sizeof(s));
if(!s.base)printf("error");
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;return(s.top);}

//CREAT 完毕。

void push(S &s,SElemType e){if(s.top-s.base==s.stacksize)
{s.base=(struct
SElemType*)realloc(s.base,(s.stacksize+STACKINCREM ENT)*sizeof(s));

if(!s.base)printf("OVERFLOW");
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;}
*s.top++=e;
}//
void Pop(S &s,SElemType e){
if(s.top==s.base)printf("error");
e=*--s.top;
}//

int m,n,i,j;
int InitMaze(int a[1000][100]){

for(j=0;j<=n+1;j++){a[0][j]=1;a[m+1][j]=1;}
for(i=0;i<=m+1;i++){a[i][0]=1;a[i][n+1]=1;}

for(i=1;i<=m;i++)
for(j=1;j<=n;j++)scanf("%d",&a[i][j]);

}

struct zuobiao NexPos(SElemType curpose,int di)
{
switch(di){
case'1': curpose.seat.j=curpose.seat.j+1;
case'2': curpose.seat.i=curpose.seat.i-1;
case'3': curpose.seat.j=curpose.seat.j-1;
case'4': curpose.seat.i=curpose.seat.i+1;
default: printf("error");
return(curpose.seat);}}

int main(){
int a[100][100];

scanf("%d,%d",&m,&n);
InitMaze(a);
InitStack(s);
curpose.seat.i=1;curpose.seat.j=1;
do{

if(!a[curpose.seat.i][curpose.seat.j])curpose.type=1;//路过留下足迹

e.seat.i=curpose.seat.i;e.seat.j=curpose.seat.j;
e.di=1;
push(s,e);
{ if(curpose.seat.i==m&&curpose.seat.j==n){
while(s.top!=s.base){Pop(s,e);
printf("(%d,%d,%d) ",e.seat.i,e.seat.j,e.di);}}}
NexPos(curpose,e.di);

if(s.top!=s.base){
while(e.di==4){a[i][j]=1;Pop(s,e);}
if(e.di<4){e.di++;
NexPos(curpose,e.di);}}
while(s.top!=s.base);
}

Apr 28 '06 #1
4 6581
zl*****@mail.ustc.edu.cn wrote:
//????
[...]


Count your curly braces. There is an opening brace somewhere
without the corresponding closing one.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 28 '06 #2
zl*****@mail.ustc.edu.cn wrote:
//????
[...]


Oh, and having characters not from the basic character set anywhere
in your code can also screw up processing. And format your source
a bit better, it will save you time doing maintenance on your code
(provided that you actually do maintain it).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 28 '06 #3
zl*****@mail.ustc.edu.cn wrote:
//迷宫问题
As Victor said, these characters will mess up many compilers.
#include<stdio.h>
#include<malloc.h>
Ick. Malloc is yucky. Learn to use new/delete.
#define sqstack S
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
struct zuobiao{
int i;
int j;
};
This is an example of the source of your problem. Line up
those curly brackets. Like so.

struct zuobiao
{
int i;
int j;
};

That old style is K&R. If you line up the { and }, it's much
easier to count and be sure you have them all matched.
(Though my development system has a "jump to matching
bracket.) And be sure to use white space effectively.

Also, whenever you add a {, add the matching } right away.
So when I put in a struct I first type in this.

struct zuobiao
{
};

Then I start adding the stuff inside the brackets.
struct SElemType{
int type;
int di;
struct zuobiao seat;};
struct sqstack{
struct SElemType *base;
struct SElemType *top;
int stacksize;}s;
This would be so much easier to read with some good white space.

struct SElemType
{
int type;
int di;
zuobiao seat;
};

struct sqstack
{
SElemType *base;
SElemType *top;
int stacksize;
};

sqstack s;
struct SElemType e,curpose;
That looks odd to my "C++" eye.

SElemType e;
SElemType curpose;

Oh, and I just noticed. These are file scope variables. Unles there
is a good reason for them (not apparent) you should reduce or
get rid of these.
struct SElemType *InitStack(S &s){
s.base=(struct SElemType*)malloc(STACK_INIT_SIZE*sizeof(s));
if(!s.base)printf("error");
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;return(s.top);}

//CREAT 完毕。
More weird chars.
void push(S &s,SElemType e){if(s.top-s.base==s.stacksize)
{s.base=(struct
SElemType*)realloc(s.base,(s.stacksize+STACKINCREM ENT)*sizeof(s));
Hmmm... You use realloc. Hmm...
if(!s.base)printf("OVERFLOW");
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;}
*s.top++=e;
}//
void Pop(S &s,SElemType e){
if(s.top==s.base)printf("error");
e=*--s.top;
}//

int m,n,i,j;
int InitMaze(int a[1000][100]){

for(j=0;j<=n+1;j++){a[0][j]=1;a[m+1][j]=1;}
for(i=0;i<=m+1;i++){a[i][0]=1;a[i][n+1]=1;}

for(i=1;i<=m;i++)
for(j=1;j<=n;j++)scanf("%d",&a[i][j]);

}
Missing return value.
struct zuobiao NexPos(SElemType curpose,int di)
{
switch(di){
case'1': curpose.seat.j=curpose.seat.j+1;
case'2': curpose.seat.i=curpose.seat.i-1;
case'3': curpose.seat.j=curpose.seat.j-1;
case'4': curpose.seat.i=curpose.seat.i+1;
default: printf("error");
return(curpose.seat);}}
You really need to use white space more effectively. That is
very hard to read. Also, do you want some break statements
in there?
int main(){
int a[100][100];

scanf("%d,%d",&m,&n);
InitMaze(a);
InitStack(s);
curpose.seat.i=1;curpose.seat.j=1;
For such a simple thing, it's very hard to read. You might
want to consider adding initialization to the ctor of a class.
do{

if(!a[curpose.seat.i][curpose.seat.j])curpose.type=1;//路过留下足迹

e.seat.i=curpose.seat.i;e.seat.j=curpose.seat.j;
e.di=1;
push(s,e);
{ if(curpose.seat.i==m&&curpose.seat.j==n){
while(s.top!=s.base){Pop(s,e);
printf("(%d,%d,%d) ",e.seat.i,e.seat.j,e.di);}}}
NexPos(curpose,e.di);

if(s.top!=s.base){
while(e.di==4){a[i][j]=1;Pop(s,e);}
if(e.di<4){e.di++;
NexPos(curpose,e.di);}}
while(s.top!=s.base);
}


Again, use whitespace more effectively, and line up your brackets
and you will spot your error much more easily.

The last } here matches up with the { at the do. But without my
editor that does "jump to matching {}" I would not have spotted it.
Socks

Apr 28 '06 #4
Puppet_Sock wrote:
zl*****@mail.ustc.edu.cn wrote:
//迷宫问题


As Victor said, these characters will mess up many compilers.
#include<stdio.h>
#include<malloc.h>


Ick. Malloc is yucky. Learn to use new/delete.


And even if you were going to use it, there's no standard header
<malloc.h>. The correct ones are <stdlib.h> or <cstdlib>.


Brian
Apr 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Heinz | last post by:
Hello, I have a project that is used by other project in my solution. This common project is also used by a VB6 application (so it is placed in GAC). Since I did this (this is what I...
4
by: Paulo Morgado [MVP] | last post by:
Hi all I keep getting this error while building a solution with more than 10 projects. The solution/projects are open only in one instance of Visual Studio 2003 and the application (Windows...
1
by: Dwayne | last post by:
I'm getting this strange error when I try to compile a project with large (100 - 200 MB) resource files. The error is as follows (I've removed the filename for simplicity): fatal error CS0009:...
6
by: Dave H | last post by:
You'll have to excuse me if I don't know what I'm talking about, but I'm new to webservices. I'm attempting to compile a C# file with csc /r:dmcorex.dll...
3
by: tovenkatesh82 | last post by:
Hi I wrote a cgi code and in output another cgi file is getting created.....just have a look on the code... #!/usr/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); die ’Some...
1
by: eshuv | last post by:
hi I am faceing this problem when comlling the .cpp file . fatal error C1004: unexpected end of file found
12
by: jonatan | last post by:
Hello All, I am making a program and need the grt_main.c but i try to compile have the error c1004.Please help me how to solve it? Thank you. --------------------Configuration: pre - Win32...
15
by: MKO32 | last post by:
After compiling my C++ file I ended up with: fatal error C1004: unexpected end-of-file found So I went true the code from the top to the bottom about six times to see if I could find a forgotten...
10
shashahayes
by: shashahayes | last post by:
This is the message I am getting when I try to compile it. fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.