红色部分没看懂,谁能给解释一下,谢谢!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ctype.h"
#define MAX 10000
void main()
{
FILE * fp;
int ch ;
int temp = -1;
int space = 0;
char array[MAX][30];
int number = 0;
int i = 0 ;
char *lest,*str;
char * p;
lest=(char *)malloc(30);
str =(char *)malloc(30);
p = str;
if(lest == NULL || str== NULL)
{
printf("分配内存失败\n");
exit(1);
}
if(NULL == (fp = fopen("1.txt","rb"))) //打开文件
{
printf("文件打开失败\n");
exit(1);
}
ch = fgetc(fp);
while(ch != EOF)
{
if( isalpha(ch) && (ispunct(temp)||isspace(temp))) //进行条件判断
space++;
temp = ch;
ch = fgetc(fp);
}
printf("In all the letter total is: %d\n",++space);
rewind(fp);
fscanf(fp,"%s",lest);
for(number = 0;number <= space;number++)
{
for(i = 0;i<=(int)strlen(lest);i++)
{
if(i<=(int)strlen(lest))
array[number][i] = '\0';
if(ispunct(*(lest+i))&&(i == (int)strlen(lest)-1)) //进行条件判断
{
array[number][i] = '\0';
break;
}
array[number][i] = *(lest+i);
}
fscanf(fp,"%s",lest);
}
fclose(fp);
for(number=0; number<=space-1;number++)
{
str = array[number];
for(i=number+1; i<=space-1;i++)
{
temp =1;
if(!strcmp(str,array[i]))
temp++;
}
printf("%20s :%d\n",str,temp);
}
free(p);
free(lest);
}