c程序设计语言有错误,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[i] = '\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 <= high) {

mid = (low + high) / 2;

if ((cond = strcmp(word, tab[mid].keyword)) < 0)

high = mid - 1;

else if (cond > 0)

low = mid + 1;

else

return mid;

}

return -1;

}

void swap(int i, int j, struct key tab[]) {

int temp;

temp = tab[i].count;

tab[i].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[i].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()))就说触发断点了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值