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

a function-definition is not allowed here before '{' token在Insert函数里面如何没有异常啊

2012-11-21 
a function-definition is not allowed here before { token在Insert函数里面怎么没有错误啊?typedef st

a function-definition is not allowed here before '{' token在Insert函数里面怎么没有错误啊?
typedef struct
{
  char *str;
  int maxLength;
  int length;
}DString;
void Initiate(DString *S, int max, char *string)
{
int i,m;
S->length = strlen(string);
if(S->length > max) m = S->length;
else m = max;
S->maxLength = m;
S->str = (char *)malloc(sizeof(char)*m); //申请动态数组空间
for(i = 0; i < S->length; i++) //赋值
  S->str[i] = string[i];
  }
int Insert(DString *S, int pos, DString T)
{ int i;  
if(pos < 0)
{  
printf("参数pos出错!");
  return 0;
  }
else
{  
if(S->length+T.length>S->maxLength)
  {
  realloc(S->str,(S->length+T.length)*sizeof(char));
  S->maxLength=S->length+T.length;  
  }
  for(i = S->length-1; i >= pos; i--)  
  S->str[i+T.length] = S->str[i];//依次后移T.length个位置
for(i = 0; i < T.length; i++)  
S->str[pos+i] = T.str[i]; //插入
S->length = S->length + T.length;
return 1;
}
 
int Delete(DString *S,int pos,int len)
{  
  int i;
if(S->length<=0)
  {  
printf("数组中未存放字符无元素可删! \n");
return 0; 
  }
else if(pos < 0 || len < 0 || pos+len > S->length)
{  
printf("参数pos和len不合法");  
return 0; 
  }
else
{
for(i = pos+len; i <= S->length-1; i++)
S->str[i-len] = S->str[i];//依次前移len个位置
S->length = S->length - len;
return 1;
}
  }
   
int SubString(DString *S,int pos,int len,DString *T)
{  
  int i;
if(pos < 0 || len < 0 || pos+len > S->length)
{  
printf("参数pos和len出错!");
  return 0; }
if(len>T->maxLength)
  { T-str=(char *)malloc(len*sizeof(char)); T-<maxLengthlen;}
for(i = 0; i < len; i++)  
T->str[i] = S->str[pos+i];
  T->length = len;  
return 1;
  }
  }
void Destroy(DString *S)
{
  free(S->str);
  S->maxLength = 0;
  S->length = 0;
}


[解决办法]
Insert函数最后少了个括号:}
[解决办法]
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。

热点排行