请问下面这个程序,除了ctrl+z结束循环外,怎样正常退出循环?
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
struct node
{
char word[122];
int num;
}N[10000];
int main()
{
int flag = 0;
char c;
int i = 0;
char name[122];
int len = 0;
for(int k = 0; k < 10001; k++)
{
memset(N[k].word, '\0', sizeof(char)*122);
N[k].num = 0;
}
while(scanf("%c", &c) != EOF)
{
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= 0 && c <= 9))
{
if(flag == 0)
{
flag = 1;
i = 0;
}
if(c >= 'A' && c <= 'Z')
c = c - 'A' + 'a';
name[i++] = c;
}
else
{
if(flag == 1)
{
flag = 0;
name[i] = '\0';
bool tag = false;
for(int j = 0; j < len; j++)
{
if(strcmp(N[j].word, name) == 0)
{
N[j].num++;
tag = true;
break;
}
}
if(!tag)
{
strcpy(N[len].word, name);
N[len++].num++;
}
}
}
}
char list[10000][122];
int max = 0, cnt = 0;
for(int k = 0; k < len; k++)
{
if(max < N[k].num)
{
max = N[k].num;
cnt = 0;
strcpy(list[cnt++], N[k].word);
}
else if(max == N[k].num)
strcpy(list[cnt++], N[k].word);
else
continue;
}
char temp[122];
for(int j = 0; j < cnt; j++)
{
for(int k = j + 1; k < cnt; k++)
{
if(strcmp(list[j], list[k]) > 0)
{
strcpy(temp, list[j]);
strcpy(list[j], list[k]);
strcpy(list[k], temp);
}
}
}
printf("%d occurrences\n", max);
for(int k = 0; k < cnt; k++)
{
printf("%s\n", list[k]);
}
return 0;
}