strstr()与strchr()都包含着<string.h>中
strchr() 字符串与字符串
原型:char * strchr(char * str, int ch)
功能:找出在字符串str中第一次出现字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针(就是 null)。
strstr() 字符串与字符
原型: char * strstr(char * str1,char * str2)
功能:找出在字符串str1中第一次出项字符串str2的位置(也就是说字符串sr1中要包含有字符串str2),找到就返回该字符串位置的指针(也就是返回字符串str2在字符串str1中的地址的位置),找不到就返回空指针(就是 null)。
P41 竖式问题
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <stdio.h> #include <string.h> int main() { char s[20],buf[99]; int abc,de,x,y,z; int i,ok = 1,count = 0; scanf("%s",s); for(abc = 111;abc<=999;abc++) { for(de = 11;de<=99;de++) { x = abc*(de%10); y = abc*(de/10); z = abc*de; sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z); //sprintf() 把信息输出到字符串,应保证字符串足够大可以容纳输出信息 ok = 1; for(i = 0;i<strlen(buf);i++) { if(strchr(s,buf[i])==NULL) ok = 0; } if(ok) { printf("<%d>n",++count); printf("%5dnX%4dn-----n%5dn%4dn-----%5dnn",abc,de,x,y,z); } } } printf("The number of solutions = %d",count); return 0; }
最后
以上就是幸福寒风最近收集整理的关于strstr()与strchr()、竖式问题的全部内容,更多相关strstr()与strchr()、竖式问题内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复