• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

c程序设计语言关于结构数组的问题,VS提示触发一个断点,请教大神哪里错了

#include
#include
#include
struct key {
char *keyword;
int count;
};
struct key tab[] = { { "art",0 },{ "hos",0 } ,{ "leg",0 },{ "lie",0 },{ "math",0 },{ "sci",0 } };
#define MAX 100
#define NKEYS (sizeof tab/sizeof (struct key))
int getword(char word[], int lim) {
word[0]='v';
      char c;
int getch(void);
void ungetch(char);
char w[MAX];
int i = 0;
int j;
while (isspace(c = getch()));
if (c != EOF)
  w[i++] = c;
if (!isalpha(c)) {
  w = '\0';
  return c;
}
for (j=0; --lim > 0; j++)
{
  if (!isalpha(w[j++] = getch())) {
   ungetch(w[j-1]);
   break;
  }
}
word = w;
return word[0];
}
int binsearch(char *word, struct key tab[], int n) {
int cond, low, high, mid;
low = 0;
high = n - 1;
while (low  0)
   low = mid + 1;
  else
   return mid;
}
return -1;
}
void swap(int i, int j, struct key tab[]) {
int temp;
temp = tab.count;
tab.count = tab[j].count;
tab[j].count = temp;
}
void qsort(struct key tab[], int left, int right) {
int i, last;
last = left;
i = left + 1;
if (left >= right)
  return;
swap(left, (left + right) / 2, tab);
last = left;
for (i = left + 1; i < right; i++) {
  if (tab.count < tab[left].count)
   swap(++last, i, tab);
}
swap(left, last, tab);
qsort(tab, left, last - 1);
qsort(tab, last + 1, right);
}
int main() {
int n;
char word[MAX] = "a";
while (getword(word, MAX) != EOF) {
  if (isalpha(word[0]))
   if (n = binsearch(word, tab, NKEYS) >= 0)
    tab[n].count++;
}
for (n = 0; n < NKEYS; n++)
  printf("选择%s的人数为%d", tab[n].keyword, tab[n].count);
qsort(tab, 0, NKEYS - 1);
printf("人数最多的学院有%d人", tab[NKEYS - 1].count);
system("pause");
return 0;
}
调试的时候到getword函数的 if (!isalpha(w[j++] = getch()))就说触发断点了

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!