buraka
2018-01-03 17:11:55
等
为什么c程序一输入用户就停止工作?
001 | #include <stdio.h> |
002 | #include <stdlib.h> |
003 | #include <string.h> |
004 |
005 | int key 1 ; |
006 | int key 2 ; |
007 | int *p; |
008 | struct node |
009 | { |
010 | char name[ 10 ]; |
011 | char address[ 20 ]; |
012 | char num[ 11 ]; |
013 | node *next; |
014 | }; |
015 |
016 | typedef node *pnode; |
017 | typedef node *xingming; |
018 | node **phone; |
019 | node **nam; |
020 |
021 | void hash 1 (char num[ 11 ]) |
022 | { |
023 | int i= 3 ; |
024 |
025 | key 1 =(int)num[ 2 ]; |
026 |
027 | while(num[i]!=NULL) |
028 | { |
029 | key 1 +=(int)num[i]; |
030 | i++; |
031 | } |
032 | key 1 =key 1% 20 ; |
033 | } |
034 | void hash 2 (char name[ 10 ]) |
035 | { |
036 | int i= 1 ; |
037 | key 2 =(int)name[ 0 ]; |
038 | while(name[i]!=NULL) |
039 | { |
040 | key 2 +=(int)name[i]; |
041 | i++; |
042 | } |
043 | key 2 =key 2% 20 ; |
044 |
045 | } |
046 |
047 | node *input() |
048 | { |
049 | node *temp; |
050 | temp= new node; |
051 | temp->next=NULL; |
052 | printf( "请输入姓名:\n" ); |
053 | scanf( "%s" ,temp->name); |
054 | printf( "输入地址:\n" ); |
055 | scanf( "%s" ,temp->address); |
056 | printf( "输入电话:\n" ); |
057 | scanf( "%s" ,temp->num); |
058 |
059 | return temp; |
060 | } |
061 | int add() |
062 | { |
063 | node *newphone; |
064 | node *newname; |
065 | newphone=input(); |
066 | newname=newphone; |
067 | hash 1 (newphone->num); |
068 | hash 2 (newname->name); |
069 | newphone->next =phone[key 1 ]->next; |
070 | phone[key 1 ]->next=newphone; |
071 | newname->next=nam[key 2 ]->next; |
072 | nam[key 2 ]->next=newname; |
073 | return 0 ; |
074 | } |
075 | void create 1 () |
076 | { |
077 | int i; |
078 | phone=new pnode[ 20 ]; |
079 | for(i= 0 ; i< 20 ; i++) |
080 | { |
081 | phone[i]=new node; |
082 | phone[i]->next=NULL; |
083 | } |
084 | } |
085 | void create 2 () |
086 | { |
087 | int i; |
088 | nam=new xingming[ 20 ]; |
089 | for(i= 0 ; i< 20 ; i++) |
090 | { |
091 | nam[i]=new node; |
092 | nam[i]->next=NULL; |
093 | } |
094 | } |
095 | void display() |
096 | { |
097 | int i; |
098 | node *p=NULL; |
099 | for(i= 0 ; i< 20 ; i++) |
100 | { |
101 | p=nam[i]->next; |
102 | while(p) |
103 | { |
104 | printf( "%s\n%s\n%s\n\n" ,p->name,p->address,p->num); |
105 | p=p->next; |
106 | } |
107 | } |
108 | } |
109 | void serch_num(char num[]) |
110 | { |
111 | hash 1 (num); |
112 | node *q=phone[key 1 ]->next; |
113 | while(q!=NULL) |
114 | { |
115 | if(strcmp(num,q->num)== 0 ) |
116 | break; |
117 | q=q->next; |
118 | } |
119 | if(q) |
120 | printf( "%s\n%s\n%s\n" ,q->name,q->address,q->num); |
121 | else printf( "无此记录\n" ); |
122 | } |
123 | void serch_name(char name[ 10 ]) |
124 | { |
125 | hash 2 (name); |
126 | node *q=nam[key 2 ]->next; |
127 | while(q!=NULL) |
128 | { |
129 | if(strcmp(name,q->name)== 0 ) |
130 | break; |
131 | q=q->next; |
132 | } |
133 | if(q) |
134 | printf( "%s\n%s\n%s\n" ,q->name,q->address,q->num); |
135 | else printf( "无此记录\n" ); |
136 | } |
137 | void menu() |
138 | { |
139 | printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" ); |
140 | printf( "@_____________请输入你的选择_______________@\n" ); |
141 | printf( "@_______0.添加记录 1.查找记录____________@\n" ); |
142 | printf( "@_______2.显示记录 3.清空记录____________@\n" ); |
143 | printf( "@________________4.退出系统________________@\n" ); |
144 | printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" ); |
145 | } |
146 | int main() |
147 | { |
148 | char num[ 11 ]; |
149 | char name[ 10 ]; |
150 |
151 | create 1 (); |
152 | create 2 (); |
153 |
154 | int select; |
155 | while( 1 ) |
156 | { |
157 | menu(); |
158 | scanf( "%d" ,&select); |
159 | switch(select) |
160 | { |
161 | case 1: |
162 | { |
163 | system( "cls" ); |
164 | printf( "6.号码查询,7.姓名查询\n" ); |
165 | int a; |
166 | scanf( "%d" ,&a); |
167 | if(a= 6 ) |
168 | { |
169 | printf( "请输入电话号码:\n" ); |
170 | scanf( "%s" ,&num); |
171 | printf( "输出查找的信息:\n" ); |
172 | serch_num(num); |
173 | } |
174 | else |
175 | { |
176 | printf( "请输入姓名\n" ); |
177 | scanf( "%s" ,name); |
178 | printf( "输出查找的信息\n" ); |
179 | serch_name(name); |
180 | } |
181 | } |
182 | break; |
183 | case 2: |
184 | { |
185 | system( "cls" ); |
186 | printf( "显示结果\n" ); |
187 | display(); |
188 | } |
189 | break; |
190 | case 0: |
191 | { |
192 | system( "cls" ); |
193 | printf( "请输入要添加的内容\n" ); |
194 | add(); |
195 | } |
196 | break; |
197 | case 3: |
198 | {<a href= "http://static.zuidaima.com/images/237173/201801/20180103171135562_w.png" target= "_blank" ><img alt= "为什么c程序一输入用户就停止工作?" data-rawwidth= "981" data-rawheight= "512" src= "https://static.zuidaima.com/resource/img/gray_loading.png" class= "lazy img-rounded" data-original= "http://static.zuidaima.com/images/237173/201801/20180103171135562_w_650x339.png" style= "width:100%;height:339px" ></a> |
199 | system( "cls" ); |
200 | printf( "列表已清空\n" ); |
201 | create 1 (); |
202 | create 2 (); |
203 | } |
204 | break; |
205 | default: |
206 | return 0 ; |
207 | } |
208 | } |
209 | return 0 ; |
210 | } |
评论
- 等 最代码怎么获取牛币啊?
- 完 谁来告诉我最代码上线的时间,答对者给5牛币,先来先得
- 等 牛友们,大家好,你们做程序员多久了?现在还好吗?
- 完 在微信打开的页面里进行app下载
- 等 最代码2014年欢乐聚声会
- 完 mysql如何查询表数据并且对3个字段降序的SQL?
- 完 最代码牛币机制改革
- 完 成功的在bae上使用了自定义运行环境 jetty+nginx的组合,大家对jetty+nginx优化有哪些心得?
- 完 进来分享一下各位牛牛是如何加入最代码大家庭的?
- 等 为什么java BufferedImage类处理大图直接抛出内存溢出的异常?
- 等 最代码是否开发手机app客户端?
- 完 java程序员学习哪些java的技术?java有哪些框架?都能做哪方面的开发?
- 等 php格式网页文件怎么运行?
- 等 Java volatile值获取的问题
- 等 前端vue,拦截了登录后台后,返回的token,requests拦截token,但是发送请求的时候,就出现跨越异常
- 等 大专本科计算机科班怎么找到Java工作?
- 等 eclipse怎么把三个java swing游戏项目合成一个项目?
- 完 伙伴们,大家都有什么好的解压方式么,分享一下~
- 完 三四线城市,6、7k,运维工作,索然无味,想去辞职上培训,各位牛牛有什么建议嘛
- 等 jsp页面输入中文变成问号
- 等 JPA在线上运行一段时间后报错Caused by: java.lang.IncompatibleClassChangeError: null
- 等 PHP 这个规则用preg_match_all怎么写
- 等 大佬们,有没有知道Alfresco如何配置LDAP登录呢?
- 等 php的install目录是框架带的吗?


asd13606410359 LV10
2020年4月8日
程序小生 LV4
2020年1月9日
srl2881552 LV10
2019年1月8日
dukerchen LV2
2018年6月4日
mayoooooo LV4
2018年3月2日
weifei LV6
2018年2月24日
yangxing033 LV1
2018年1月25日
buyaobilian LV3
2018年1月19日
wenwenlife LV6
2018年1月15日
低调人 LV38
2018年1月13日