l30.1a

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1A 代码 · 共 46 行

1A
46
字号
#printWrite a subroutine named "locn(s,c)" which expects twoarguments: the first is a pointer to characters 's' whichpoints to a null-terminated string, and the secondis a character 'c' which is to be searched for in thestring 's'.  If the character 'c' does notappear in the string return 0; otherwise return a pointerto the position of 'c' in the string. Name the program "locn.c";as usual, compile and test it and then type "ready".#once #create Ref0190250#once #create tzaqc.cchar *alpha "abcdefghijklmnopqrstuvwxyz";main(){	extern char *locn();	printf("%d\n", locn(alpha, '+'));	printf("%d\n",locn(alpha, 't')-alpha);	printf("%d\n",locn(alpha, 'a')-alpha);	printf("%d\n",locn(alpha, 'z')-alpha);	printf("%d\n",locn("", 'z'));}#usercc tzaqc.c locn.oa.out  >value#cmp value Ref#succeed/* Try this: */char *locn (s, c)char *s;{	for( ; *s; s++)		if (*s == c)			return(s);	return(0);}#log#next31.1a 10

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?