When I was finishing exercise 6.2, this is what it says:
Exercise 6-2. Write a program that reads a C program and prints in alphabetical order each group of variable names that are identical in the first 6 characters, but different somewhere thereafter . Don't count words within strings and comments. Make 6 a parameter that can be set from the command line.
Unfortunately I was NOT able to understand something like this
prints in alphabetical order each group of variable names that are identical in the first 6 characters
Could someone explain it a bit to me? Given the c program I am about to read is the following:
int 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(my_getline(line,MAXLINE) > 0){ lineno++; if ((strstr(line, *argv) != NULL) != except){ if (number) printf("%ld", lineno); printf("%s", line); found++; } } return found; }
Hope the C program to be read is not complex.
https://stackoverflow.com/questions/67239262/my-question-about-the-question-itself-of-kr-c-book-exercise-6-2 April 24, 2021 at 12:12PM
没有评论:
发表评论