Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uwm.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!nnj20229 From: nnj20229@uxa.cso.uiuc.edu (Nesha Nicole Jones) Newsgroups: comp.lang.c Subject: input to a function Summary: Allowing piped input into a function or program Keywords: input function Message-ID: <1991May30.191116.19256@ux1.cso.uiuc.edu> Date: 30 May 91 19:11:16 GMT Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 40 I wrote a program that acts like a grep only it greps the line you are looking for and the line above it. I would like to be able to do something like: rest "restart" /usr/bin/adm/sa/sar24 or rest "restart" < /usr/bin/adm/sa/sar24 currently my program does the second of the two listed above. If I use file pointers and fopen will the program still work if I try to pipe input into it? below are the two functions I currently use to get the line and check to see if the string is in the line. int getline(char s[], int lim) /* reads in the line from the file/stdin */ { 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); } /* if the following function returns a value greater than 0 the it writes the line that was rad in getline to to the screen */ int index(char s[], char t[]) { int i,j,k; for (i = 0; s[i] != '\0'; i++) { for (j = i, k = 0; t[k] !='\0' && s[j] == t[k]; j++,k++) ; if (t[k] == '\0') return(i); } return(-1); }