首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

pku oj的1002题,该如何处理

2012-10-20 
pku oj的1002题在codeblocks和vs2010上编译运行结果都正确 为什么 上传就说Compile ErrorMain.cF:\temp\10

pku oj的1002题
在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


代码贴上

C/C++ code
#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);} 



[解决办法]
如果以".c"保存,将下面两行的顺序互换一下(C语言变量声明在前):
scanf("%d",&tel_num);
struct tel *p_tel=(struct tel*)malloc(sizeof(struct tel)*tel_num);
否则将扩展名改为:.cpp试试;

[解决办法]
C89和C++的区别,C89必需在作用域头部声明变量

热点排行