Joke Collection Website - News headlines - How to write a program to calculate the number of names in C language? Urgent! Urgent! Urgent! ! ! !

How to write a program to calculate the number of names in C language? Urgent! Urgent! Urgent! ! ! !

The code is as follows:

# include & ltstdio.h & gt

# include & ltstring.h & gt

# include & ltstdlib.h & gt

int main()

{

Struct person /* defines the structure */

{

char name【20】; /* The default name is no more than 20 characters, and there are no spaces. */

Int time/* Number of occurrences */

};

Constructing personal data [200]; /* Default does not exceed 200 different names */

int I;

for(I = 0; I & lt200; I++)/* Initialize it */

{

Data [I]. name【0】= 0;

Data [I]. time = 0;

}

char temp【20】;

int total = 0; /* There were 0 people at the beginning * * *

while(scanf(“% s“,temp)! = EOF)/* Cycle through all names */

{

int I = 0;

for(I = 0; I < total; I++)/* Compare with existing names to see if they are the same */

{

if(strcmp(temp,data【I】)。 Name)= 0)/* If they are the same */

{

Data [I]. time++;

Break;

}

}

If(I = = total)/* searched around and found no existing one, which proves that the name has never appeared. Save a new */

{

Strcpy (data [total]). Name, temporary);

Data [total]. time = 1;

Total++;

}

}

for(I = 0; I < total; I++)/* Final loop output result */

printf(“% s-% d \ n“,data【I】。 Name and data [i]. Time);

System ("suspended");

Returns 0;

}

I wish you progress in your study!