본문/내용
4.1 함수의 기초
#include
#define MAXLINE 1000 /* maxium input line length */
#define EOF `.`
int getline(char [], int);
int strindex(char [], char []);
char pattern[] = `ould`; /* pattern to search for */
/* find all lines matching patterns */
void main(void)
{char line[MAXLINE];
while (getline(line, MAXLINE) > 0)
if (strindex(line, pattern) >= 0)
printf(`%s`,line);
}
/* getline: get line into s, return length */
int getline(char s[], int lim)
{int c, i;i = 0;while (--lim>0 && (c=getchar()) != EOF && c != `\\n`)
s[i++] = c;if (c == `\\n`)s[i++] = c;
s[i] = `\\0`;
return i;}
/* strindex: return index of t in s, -1 if none */
int strindex(char s[], char t[])
{int i,j,k;for(i = 0; s[i] != `\\0`; i++) {or (j=i, k=0; t[k] != `\\0` && s[j]==t[k]; j++, k++)
;
if (k > 0 && t[k] == `\\0`)return i;}
return -1;}
※ return 문
· 함수를 수행한 결과값을 되돌려준다.
· 프로그램 실행중 return 문을 만나면 함수의 실행은 무조건 종료된다.
· retu…