c语言编程 scant,C语言编程练习章.doc

C语言编程练习章.doc

第11章 字符串和字符串函数编程练习 1设计并测试一个函数,可以从输入读取n个字符(包括空格、制表符和换行符),把结果存储在一个数组中,这个数组的地址通过参数来传递。 include stdio.hvoid char *p, int n;int mainvoid char a81; int n; puts the char number of your string; scanfd,n; getchar; 滤去回车 puts your string; a,n; putsa; return 0;void char *p, int n int i; for i0;in;i *pi getchar; *pi 0stdio.hinclude ctype.hvoid char *p, int n;int mainvoid char a81; int n; puts the char number of your string; scanfd,n; getchar; 滤去回车 puts your string; a,n; putsa; return 0;void char *p, int n int i; for i0;in;i *pi getchar; if isspace*pi break; *pi 0stdio.hinclude ctype.hvoid wordchar *p;int mainvoid char a81; puts your string; getsa; worda; putsa; return 0;void wordchar *p int begin,end; forbegin0; isspace *pbegin ;begin continue; forendbegin; isspace *pend ;end continue; *pend 0 *p begin 0 *p 0stdio.hchar *mystrchrchar *, char ;int mainvoid char str81; char ch; char *p; do puts range string; getsstr; puts match char; ch getchar; getchar; p mystrchrstr, ch; if p putsFind; putsp; else putsCant find; puts any char except q to go on.; getsstr; while*str q; putsQuit.; return 0;char *mystrchrchar *p, char ch char *p_save p; if*p 0 return NULL; while1 if*p ch return p_save; else if*p 0 return NULL; p_save p; 5编写一个函数is_witlun。它接受两个参数,一个是字符,另一个是字符串指针。其功能是如果字符在字符串中,就返回一个非O值(真);如果字符不在字符串中,就返回O值(假)。在一个使用循环语句为这个函数提供输入的完整程序中进行测试。 include stdio.hint is_withinchar *p, char ch;int mainvoid char str81; char ch; do puts range string; getsstr; puts match char; ch getchar; getchar; if is_withinstr, ch putsFind; else putsCant find; puts any char except q to go on.; ch getchar; getchar; whilech q; putsQuit.; return 0;int is_withinchar *p, char ch while*p 0 if*p ch return 1; p; return 0; 6strncpy sl,s2,n函数从s2复制n个字符给sl,并在必要时截断s2或为其填充额外的空字符。如果s2的长度等于或大于n,目标字符串就没有标志结束的空字符。函数返回sl。自己编写这个函数,并在一个使用循环语句为这个函数提供输入的完整程序中进行测试。 include stdio.hchar *mystrncpychar *p1, char *p2, int n;int mainvoid char str181; char str281; int n; do puts string1; getsstr1; puts string2; getsstr2; puts the number of copying char; scanfd,n; getchar; putsAfter copying; putsmystrncpystr1, str2, n; puts any char except q to go on.; getsstr1; while*str1 q; putsQuit.; return 0;char *mystrncpychar *p1, char *p2, int n char *pp1; while*p1 0 continue; *p1 *p2; n; whilen0 *p2 0 *p1 *p2; n; return p; 7编写一个函数string_in,它接受两个字符串指针参数。如果第二个字符串被包含在第一个字符串中,函数就返回被包含的字符开始的地址。例如,string_inhats,at返回hats中a的地址,则,函数返回空指针。在一个使用循环语句为这个函数提供输入的完整程序中进行测试。 include stdio.hchar *string_inchar *p1, char *p2;int mainvoid char str181; char str221; char *p; do puts range string; getsstr1; puts match string; getsstr2; p string_instr1, str2; if p putsFind; putsp; else putsCant find; puts any char except q to go on.; getsstr1; while*str1 q; putsQuit.; return 0;char *string_inchar *p1, char *p2 char *p1_save p1, *p2_save p2; if*p1 0 *p2 0 return NULL; while1 if*p1 *p2 if*p2 0 return p1_save; if*p1 0 return NULL; else if*p1 0 return NULL; p1_save p1; p2 p2_save; 8编写一个函数,其功能是使输入字符串反序。在一个使用循环语句为这个函数提供输入的完整程序中进行测试。 include stdio.hvoid reversechar *p;int mainvoid char str81; do puts a string; getsstr; reversestr; putsstr; puts any char except q to go on.; getsstr; while*str q; putsQuit.; return 0;void reversechar *p int i,n; char temp; forn0; *pn 0 n; fori0; i n-i; i temp pi; pi pn-i; pn-i temp; 9编写一个函数。其参数为一个字符串,函数删除字符串中的空格。在一个可以循环读取的程序中进行测试,直到用户输入空行。对于任何输入字符串,函数都应该适用并可以显示结果。 include stdio.hvoid delspacechar *p1;int mainvoid char str81; do puts a string; getsstr; delspacestr; putsstr; puts any char except q to go on.; getsstr; while*str q; putsQuit.; return 0;void delspacechar *p1 char *p2; while *p1 0 if *p1 p2 p1; while*p2 0 *p2 *p21; p2; p1; 抵消下面的p1 p1; 10.编写一个程序,读取输入,直到读入了10个字符串或遇到EOF,由二者中最先被满足的那个终止读取过程。这个程序可以为用户提供一个有5个选项的菜单输出初始字符串列表、按ASCII顺序输出字符串、按长度递增顺序输出字符串、按字符串中第一个单词的长度输出字符串和退出。菜单可以循环,直到用户输入退出请求。当然,程序要能真正完成菜单中的各项功能。 include stdio.hinclude string.hinclude ctype.hvoid origin_putchar p, int n;void ascii_putchar p, int n;void length_putchar p, int n;int first_word_lengthchar *p;int first_word_lengthchar *p;void word_putchar p, int n;int mainvoid char str1081; char *p10; char command10; int n; while1 n 0; puts no more than 10 strings finished by EOF Z; do if getsstrn NULL break; pn strn; n; while n10 ; putsselect; putsa. put originally; putsb. put in order of ascii; putsc. put in order of strings length; putsd. put in order of first words length; putse. strings again; putsq. quit; do getscommand; switchcommand0 case a putsput originally; origin_putp,n; break; case b putsput in order of ascii; ascii_putp,n; break; case c putsput in order of strings length; length_putp,n; break; case d putsput in order of first words length; word_putp,n; break; case e break; default putsQuit.; return 0; while command0 e ; void origin_putchar p, int n int i; fori0; in; i putspi;void ascii_putchar p, int n int i,j; char *temp; fori0; in; i forj0; jn-i-1; j if strcmp pj, pj1 0 temp pj; pj pj1; pj1 temp; origin_putp,n;void length_putchar p, int n int i,j; char *temp; fori0; in; i forj0; jn-i-1; j if strlenpj strlenpj1 temp pj; pj pj1; pj1 temp; origin_putp,n;int first_word_lengthchar *p int i0; for ; isalpha*p; p if *p 0 return 0; for i1; isalphapi; i continue; return i;void word_putchar p, int n int i,j; char *temp; fori0; in; i forj0; jn-i-1; j if first_word_lengthpj first_word_lengthpj1 temp pj; pj pj1; pj1 temp; origin_putp,n; 11.编写一个程序。功能是读取输入,直到遇到EOF,并报告单词数、大写字母数、小写字母数、标点符号数和数字字符数。使用ctype.h系列的函数。 include stdio.hinclude ctype.hint mainvoid int word0,upper0,lower0,punct0,digit0,begin0; char ch; while ch getchar EOF if isalphach if begin 0 word; begin 1; else begin 0; if isupperch upper; if islowerch lower; if ispunctch punct; if isdigitch digit; printfworddnupperdnlowerdnpunctdndigitdn,word,upper,lower,punct,digit; return 0; 12.编写一个程序,按照相反的单词顺序显示命令行参数。即,如果命令行参数是see you later,程序的显示应该为later you see。 include stdio.hinclude string.hinclude ctype.hint mainvoid char str81; char *p, temp; int i,n,length; getsstr; for p str,i0,n strlenstr; in/2; i将整个字符串倒序 temp *pn-1-i; *pn-1-i *pi; *pi temp; putsstr; p str; length0; do 将字符串中的每个单词倒序 if isalpha*p length; else iflength1 fori0; ilength/2; i temp *p-1-i; *p-1-i *p-lengthi; *p-lengthi temp; length 0; while*p 0; putsstr; return 0; 13.编写一个计算乘幂的基于命令行的程序。第一个命令行参数为double类型数,作为幂的底数;第二个参数为整数,作为幂的指数。 include stdio.hdouble mypowerdouble base, int exp;int mainvoid double base; int exp; printf base number and exp; scanflfd, base, exp; printfgd gn, base, exp, mypowerbase,exp ; return 0;double mypowerdouble base, int exp double power 1; if exp0 power 1/mypowerbase, -exp; else if exp0 while exp 0 power * base; else ifbase0 power 1; else power 1/base;0的0次幂应是一个无意义数 return power; 14.使用字符分类函数实现atoi函数。 include stdio.hinclude stdlib.hinclude ctype.hdouble myatofchar *p;int mainvoid char a300; whilea0 q puts a double without -e; getsa; printfatof .5lfn,atofa; printfmyatof .5lfn,myatofa; printfdifference.5lfn, atofa -myatofa; puts any char except q to go on.; getsa; putsQuit.; return 0;double myatofchar *p将字符串转换为浮点型,暂时只限小数点格式(如342.678) double n0; int i-1; while 1 if isdigit*p 如果是数字 n n*10 *p -0 小数位数i计数 else if *p . i -1 如果是第一个小数点 i0; 开启小数位数i计数 else break; p; for; i0; i 根据小数位数i,将n取为原来的10i分之一 n / 10; return n; 15,编写一个程序,其功能是读取输入,直到遇到文件结尾,并把文件显示出来。要求程序可以识别并执行下面的命令行参数 -p 按照原样显示输入 -u 把输入全部转换为大写 -l 把输入全部转换为小写 include stdio.hinclude ctype.hint mainint argc, char *argv char ch; if argv10 - 注意argv0是的路径,所以参数是argv1、argv2 if argv11 u while chgetchar EOF putchar toupperch ; else if argv11 l while chgetchar EOF putchar tolowerch ; else if argv11 p while chgetchar EOF putcharch; return 0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值