pku oj的1002题

wzw_0827 2012-09-29 01:50:25
在codeblocks和vs2010上编译运行结果都正确 为什么 上传就说Compile Error

Main.c
F:\temp\10866305.72650\Main.c(16) : error C2143: syntax error : missing ';' before 'type'
F:\temp\10866305.72650\Main.c(20) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(20) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(21) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(21) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(22) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(22) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(22) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(22) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(22) : error C2168: 'strlen' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(22) : error C2198: 'change' : too few arguments for call
F:\temp\10866305.72650\Main.c(30) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(30) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(30) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(30) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(30) : error C2168: 'strcmp' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(33) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(33) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(33) : error C2168: 'strcpy' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(34) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(34) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(34) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(34) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(34) : error C2168: 'strcpy' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(35) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(35) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(35) : error C2168: 'strcpy' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(39) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(39) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(39) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(39) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(39) : error C2168: 'strcmp' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(41) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(41) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(46) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(46) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(46) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(46) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(46) : error C2168: 'strcpy' : too few actual parameters for intrinsic function
F:\temp\10866305.72650\Main.c(61) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(61) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(66) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(66) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(68) : error C2065: 'p_tel' : undeclared identifier
F:\temp\10866305.72650\Main.c(68) : error C2109: subscript requires array or pointer type
F:\temp\10866305.72650\Main.c(74) : error C2065: 'p_tel' : undeclared identifier


代码贴上
#include <stdio.h>
#include<malloc.h>


struct tel
{
//char *num;//wrong
char num[15];
int n;
};
void change(char *,int);
int main()
{
int tel_num=0;
int i=0,j=0;
scanf("%d",&tel_num);
struct tel *p_tel=(struct tel*)malloc(sizeof(struct tel)*tel_num);

for(i=0;i<tel_num;i++)//get/deal tel nums
{
//gets(p_tel[i].num);
scanf("%s",p_tel[i].num);
p_tel[i].n=0;
change(p_tel[i].num,strlen(p_tel[i].num));//deal with
}
int q;

for(i=0;i<tel_num-1;i++)//sort of tel_num
{
for(j=0;j<tel_num-1-i;j++)
{
if(strcmp((p_tel[j].num),(p_tel[j+1].num))>0)
{
char m[8];
strcpy(m,p_tel[j].num);
strcpy(p_tel[j].num,p_tel[j+1].num);
strcpy(p_tel[j+1].num,m);


}
else if(strcmp((p_tel[j].num),(p_tel[j+1].num))==0)
{
p_tel[j].n++;
tel_num--;

for(q=j;q<tel_num;q++)
{
strcpy(p_tel[q].num,p_tel[q+1].num);

}
j--;//for three and more same tel_num

}
/*
printf("begin i=%d,j=%d\n",i,j);
for(q=0;q<tel_num;q++)//check of scanf
{
puts(p_tel[q].num);
//puts(change(p_tel[i].num,strlen(p_tel[i].num)));}

}
*/

}
}

for(j=0;j<tel_num;j++)
{
for(i=0;i<3;i++)
{
printf("%c",p_tel[j].num[i]);
}
printf("-");
for(i=3;i<7;i++)
{
printf("%c",p_tel[j].num[i]);
}
printf(" %d\n",p_tel[j].n);

}



free(p_tel);
return 0;
}

void change(char *p,int len)
{
//printf("Len=%d\n",len);
char* ans=(char*)malloc(sizeof(char)*(len+1));

int i=0;
int j=-1;
for(i=0;i<len;i++)
{
switch(p[i])
{
case '1':
j++;
ans[j]='1';
break;
case 'A':
case 'B':
case 'C':
case '2':
j++;
ans[j]='2';
break;
case 'D':
case 'E':
case 'F':
case '3':
j++;
ans[j]='3';
break;
case 'G':
case 'H':
case 'I':
case '4':
j++;
ans[j]='4';
break;
case 'J':
case 'K':
case 'L':
case '5':
j++;
ans[j]='5';
break;
case 'M':
case 'N':
case 'O':
case '6':
j++;
ans[j]='6';
break;
case 'P':
case 'R':
case 'S':
case '7':
j++;
ans[j]='7';
break;
case 'T':
case 'U':
case 'V':
case '8':
j++;
ans[j]='8';
break;
case 'W':
case 'X':
case 'Y':
case '9':
j++;
ans[j]='9';
break;
case '0':
j++;
ans[j]='0';
break;

}

}

ans[++j]=0;
strcpy(p,ans);
free(ans);
}

...全文
238 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
AndyZhang 2012-10-01
  • 打赏
  • 举报
回复
把该加的头文件都加上,用C++编译器边
AndyZhang 2012-09-30
  • 打赏
  • 举报
回复
这个最好用C++编译器,.cpp文件
kakaximodo 2012-09-30
  • 打赏
  • 举报
回复
也是用codeblocks调试的,保存为*.cpp[Quote=引用 9 楼 的回复:]

在我的系统上只报了strlen等函数未定义
添加上#include <string.h>就OK了

另外tel *p_tel=(tel*)malloc(sizeof(tel)*tel_num); c++里可以不加struct关键字的
[/Quote]
kakaximodo 2012-09-30
  • 打赏
  • 举报
回复
在我的系统上只报了strlen等函数未定义
添加上#include <string.h>就OK了

另外tel *p_tel=(tel*)malloc(sizeof(tel)*tel_num); c++里可以不加struct关键字的
huangxy10 2012-09-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

C89和C++的区别,C89必需在作用域头部声明变量
[/Quote]

mark
jackyjkchen 2012-09-29
  • 打赏
  • 举报
回复
C89和C++的区别,C89必需在作用域头部声明变量
wzw_0827 2012-09-29
  • 打赏
  • 举报
回复
恩恩 确实是这个问题 以前也遇到过 这次一下子没想起来
但还是结果错误 我再自己想下哪里的问题 谢谢了[Quote=引用 2 楼 的回复:]

如果以".c"保存,将下面两行的顺序互换一下(C语言变量声明在前):
scanf("%d",&tel_num);
struct tel *p_tel=(struct tel*)malloc(sizeof(struct tel)*tel_num);
否则将扩展名改为:.cpp试试;
[/Quote]
huangxy10 2012-09-29
  • 打赏
  • 举报
回复
还是有c++的编译器吧,确实有点问题,不过你的程序好像结果也有问题。
huangxy10 2012-09-29
  • 打赏
  • 举报
回复
给个poj上的链接,我看不到题目?
冷月清晖 2012-09-29
  • 打赏
  • 举报
回复
我用VS2012 控制台程序调试没问题啊
Bill Adams 2012-09-29
  • 打赏
  • 举报
回复
如果以".c"保存,将下面两行的顺序互换一下(C语言变量声明在前):
scanf("%d",&tel_num);
struct tel *p_tel=(struct tel*)malloc(sizeof(struct tel)*tel_num);
否则将扩展名改为:.cpp试试;
wzw_0827 2012-09-29
  • 打赏
  • 举报
回复
有的注释不用管 是之前调试的
长了点 麻烦各位了 纠结好久了 就是不知道什么原因
它提示的错误好像没问题啊

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧