Classic pointer Expression program--a simple version of the Find command implementation

Source: Internet
Author: User

#include <stdio.h>
#include <string.h>
#define MAXLINE 1000
int Getline (char *line, int max);
/* Find:print lines that match pattern from 1st ARG */
Main (int argc, char *argv[])
{
Char Line[maxline];
Long Lineno = 0;
int C, except = 0, Number = 0, found = 0;
while (--ARGC > 0 && (*++ARGV) [0] = = '-')
while (c = *++argv[0])
Switch (c) {
Case ' x ':
except = 1;
Break
Case ' n ':
Number = 1;
Break
Default
printf ("Find:illegal option%c\n", c);
ARGC = 0;
Found =-1;
Break
}
if (argc! = 1)
printf ("Usage:find-x-n pattern\n");
Else
while (Getline (line, MAXLINE) > 0) {
lineno++;
if (Strstr (line, *argv)! = NULL)! = except) {
if (number)
printf ("%ld:", Lineno);
printf ("%s", line);
found++;
}
}
return found;
}

Classic pointer Expression program--a simple version of the Find command implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.