* Structure-04. Enter and display the address book,-04 address book

Source: Internet
Author: User

* Structure-04. Enter and display the address book,-04 address book

1 / *
2 * Main. C
3 * f4-structure -04. Input and display of address book
4 * Created on: August 26, 2014
5 * Author: Boomkeeper
6 ********* ****
7 * /
8
9 # include < stdio, h >
10 / * *
11 * address book structure
12 * /
13 struct contact {
14 char name [11]; // "name" is not more than 10 characters
15 char birthday [11]; // birthday is given as "yyyy/mm/dd"
16 char gender; // use "M" for "male" and "F" for "female"
17 char tel [16]. // "fixed-line" and "mobile phone" are consecutive digits with no more than 15 digits. "+" may appear before them.
18 char mobile [16].
19};
20
21 int main (void) {
22
Int n; // N in the problem
24
25 the scanf (" % d ", & n);
26 getchar ();
27 / * *
28 * create an array of contact types to store the address book
29 * /
30 struct contact contacts [n].
31 / * *
32 * enter address book
33 * /
34 int I;
35 for (I = 0; I < n. I++) {
36 scanf("%s %s %c %s %s",
37 contacts [I]. The name,
38 the contacts [I]. Birthday,
39 & (contacts [I]. Gender).
40 contacts [I]. Tel,
41 contacts [I]. Mobile);
42 getchar ();
43}
44
45 int k; // K in the problem
46 int search [11]; // record the serial number (serial number) to be inquired
47
48 the scanf (" % d ", & k);
49 for (I = 0; I < k; I++)
50 the scanf (" % d ", & search [I]);
51 / * *
52 * output
53 * /
54 for (I = 0; I < k; I++) {
55 if (search[I] < n && search[I] >= 0)//n address books numbered 0 to n-1
Printf ("%s %s %s %c %s\n",
57 contacts [search [I]]. The name,
58 contacts [search [I]]. Tel,
The contacts of 59 [search [I]]. Mobile,
60 contacts [search [I]]. Gender,
61 contacts [search [I]]. Birthday);
62 the else
63 printf (" Not Found \ n ");
64}
65
66 return 0;
67} 

 

It took me a long time to finish this question. (⊙ o ⊙) It took only 10 minutes !!! No (qu) tolerance (ta) Straight (ma) depending on (d), how can 9.6 be good... the question of 10 points has not passed completely, sang Xin...

It is expected that PAT (Basic Level) will be available tonight.

 

Question link:

Http://pat.zju.edu.cn/contests/basic-programming/%E7%BB%93%E6%9E%84-04

Refer:

Http://www.cnblogs.com/aexin/p/3903375.html? Utm_source = tuicool

 

 

.

 


C Address Book Management System 1. Problem description: This system enables you to input, display, change, delete, insert, and sort Address Book information.

Topic: Address Book Management System 1. Problem description: This system enables you to enter, display, modify, delete, insert, sort, and save Address Book information. Ii. Functional requirements: 1: The system uses

C language for Address Book, you only need to add and display contact data, query by name can use the structure array code is as follows

Are you sure you have sent the complete message?
Why are there so many missing items?
Where is your chaxun function ???
Where does M come from when I declare a struct variable ???
I changed it for you. It is basically the same.
# Include <stdio. h> # include <string. h ># define M 5 // define the struct tongxunlu {char name [20]; char tel [10] ;}; // compile the query function (1) enter the name of the person to be queried (2) traverse the array: Use a loop to determine whether the value of the name Member of the array element is equal to that of the input item. If so, locate and display the element and exit the loop. Void chaxun (struct tongxunlu su [M]) {char * q; int I; printf ("Enter the name to query: \ n"); scanf ("% s ", q); for (I = 0; I <M; I ++) {if (strcmp (su [I]. name, q) = 0) {printf ("result: % s \ n", su [I]. name, su [I]. tel); break ;}}// write the main function (1) Declare the structure array (2) input the name and phone number cyclically, and save it to the array (3) call the query function void main () {char * p; int I; struct tongxunlu su [M]; printf ("enter your name and phone number: \ n "); for (I = 0; I <M; I ++) scanf ("% s", su [I]. name, su [I]. tel); chaxun (su );}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.