HP C/iX Library Reference Manual (30026-90004)
344 Chapter5
HP C/iX Library Function Descriptions
strncmp
exit(2);
}
fp = fopen(argv[1], "r");
if(fp == NULL) {
fprintf(stderr, "Can't open %s.\n", argv[1]);
exit(1);
}
while(fgets(line, 100, fp) != NULL) {
if(strncmp(line, ".SH", 3) == 0)
else if(strncmp(line, ".PP", 3) == 0)
else if(strncmp(line, ".TP", 3) == 0)
else if(strncmp(line, ".RS", 3) == 0)
else if(strncmp(line, ".RE", 3) == 0)
else if(strncmp(line, ".PD", 3) == 0)
else if(strncmp(line, ".IP", 3) == 0)
else if(line[0] == '.')
}
printf("No. of .SH's: %d\n", nsh);
printf("No. of .PP's: %d\n", npp);
printf("No. of .TP's: %d\n", ntp);
printf("No. of .RS's: %d\n", nrs);
printf("No. of .RE's: %d\n", nre);
printf("No. of .PD's: %d\n", npd);
printf("No. of .IP's: %d\n", nip);
printf("No. of misc. macros: %d\n", nmisc);
fclose(fp);
exit(0);
}
In the program above, strncmp() compares the first three characters of each line read. If
the first three characters match a particular macro, the appropriate counter is
incremented. If the line begins with ".", but is not one of the macros being searched for, the
"miscellaneous" counter is incremented. The total number of lines in the file is also given.
See Also
strcmp(), strcoll(), memcmp(), ANSI C 4.11.4.4, POSIX.1 8.1