16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C Programming – Basics<br />

default: printf("find: illegal option %c\n", c);<br />

argc=0; found=-1; break;<br />

}<br />

if (argc != 1)<br />

printf("usage: find -x -n pattern\n");<br />

else<br />

while (getline(line, MAXLINE) > 0)<br />

{<br />

lineno++;<br />

if ((strstr(line, *argv) != NULL) != except)<br />

{<br />

if (number)<br />

printf("%ld:", lineno);<br />

printf("is", line);<br />

found++;<br />

}<br />

}<br />

return found;<br />

}<br />

Pointers to Functions<br />

It is possible to define pointers to functions, which can be assigned, placed in all's, passed to functions, returned by<br />

functions, and so on.<br />

e.g.<br />

void qsort(void *lineptr[J, int left, int right,<br />

int(*comp)(void *, void *));<br />

/* this declaration says that comp is a pointer to a function */<br />

/* that has two void* arguments and returns an int */<br />

/* <strong>the</strong> call to this function is as follows */<br />

qsort((void **) lineptr, 0, nline-1,<br />

(int (*)(void*, void*))(numeric ? numcmp : strcmp));<br />

/* numcmp compares two strings numerically */<br />

for (i=left+1; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!