PRODUCT : Borland C++ NUMBER : 1713 VERSION : All OS : All DATE : October 25, 1993 PAGE : 1/2 TITLE : Detecting a Blank Line /* BLANKLIN.C: Example of how to detect a blank line. This example uses the library function strpbrk which compares a string str1 against another string str2. If any character in str2 exists in str1, strpbrk returns a pointer to the character in str2. If there is no match strpbrk returns NULL. The following example loads str2 with all non-Blank ASCII characters. If strpbrk returns NULL, we know that there are only blank characters in str1. Note: In practical uses of this function, one might want to trim the size of the buffer nonBlank down to its minimum. The code here uses a length of 255 for the purpose of clarity. 255 will cover all ASCII codes, but nonBlank isn't going to contain all ASCII codes. Therefore the practical programmer might want to examine nonBlank in the debugger to see exactly what minimum length is required and change the buffer size accordingly. */ #include #include #include #ifdef __cplusplus const int MaxLine = 120; const int MaxASCII = 255; #else # define MaxLine 120 # define MaxASCII 255 #endif int main (void) { FILE *fp; char buf [MaxLine]; int i; char ni; char *notABlankLine; char nonBlank [MaxASCII]; PRODUCT : Borland C++ NUMBER : 1713 VERSION : All OS : All DATE : October 25, 1993 PAGE : 2/2 TITLE : Detecting a Blank Line for (i = 1, ni = 0; i <= MaxASCII; i++) { /* Fill up nonBlank with all non-blank ASCII characters. Note that i starts with 1 to avoid putting the NULL terminator at beginning of the string. */ if (!isspace (i)) { nonBlank [ni++] = i; } } fp = fopen ("BLANKLIN.CPP", "rt"); if (!fp) printf ("Open failed!\n"); else { while (fgets (buf, MaxLine - 1, fp)) { /* Get lines until EOF is reached. */ notABlankLine = strpbrk (buf, nonBlank); if (notABlankLine) printf ("Line '%s' is not blank.\n", buf); else printf ("Line '%s' is a blank line.\n", buf); } printf ("End of File\n"); fclose (fp); } return 0; } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.