您的位置:首页 > 其它

程序报错找不到原因高手进来看看

2014-06-13 16:40 197 查看
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int *JosephWithArray(int n)
{
int *p;
p = new int
;
int i;
for(i=0;i<n;i++)
{
p[i]=i+1;
}
return p;
}
int NextPeople(int prev,int *WorkingArray,int number_of_people,int step)
{
int count=0;
int travel=prev;
int emptyplace=0;
while(count<step)
{
travel=(travel+1)%number_of_people;
if(WorkingArray[travel])
{
count++;
emptyplace=0;
}
else
{
emptyplace++;
if(emptyplace==number_of_people)
{
return -1;
}
}
}
return travel;
}
void CreatOutput(int *WorkingArray,int number_of_people,int step)
{
int i;
int outnum=-1;
for(i=0;i<number_of_people;i++)
{
outnum=NextPeople(outnum,WorkingArray,number_of_people,step);
assert(outnum>-1 && outnum<number_of_people);
printf("%d",WorkingArray[outnum]);
WorkingArray[outnum]=0;
}
printf("\n");
}
void Dispose(int *WorkingArray)
{
delete[] WorkingArray;
}

int main()
{
int n,m;
int *WorkingArray;

printf("input number of people:");
scanf("%d",&n);
printf("input step:");
scanf("%d",&m);

WorkingArray = JosephWithArray(n);
CreatOutput(WorkingArray,n,m);
Dispose(WorkingArray);

return 0;
}
Compiling...

1234.c

F:\测试代码\1234.c(8) : error C2065: 'new' : undeclared identifier

F:\测试代码\1234.c(8) : warning C4047: '=' : 'int *' differs in levels of indirection from 'int '

F:\测试代码\1234.c(8) : error C2143: syntax error : missing ';' before 'type'

F:\测试代码\1234.c(9) : error C2143: syntax error : missing ';' before 'type'

F:\测试代码\1234.c(10) : error C2065: 'i' : undeclared identifier

F:\测试代码\1234.c(55) : error C2065: 'delete' : undeclared identifier

F:\测试代码\1234.c(55) : error C2059: syntax error : ']'

执行 cl.exe 时出错.

1234.obj - 1 error(s), 0 warning(s)

看看这是怎么回事尽量说详细点
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐