-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Inconsistent Syntax Highlight for C functions from stdio.h
On StackOverflow when answering questions, highlightjs fails to apply consistent syntax highlighting to many functions, but this is particularly acute when it applies (or fails to apply) consistent syntax highlighting to functions from the same standard header stdio.h
For example:
The functions fputs()
and puts()
are highlighted, but fopen()
, fgetc()
and fclose()
all have no highlight applied at all. The is confusing to new programmers wondering why some functions are one color and some are not.
This applies to C, but is applicable to C++ as well
Here is the link to the answer: Strncat causes exception
Are you using highlight
or highlightAuto
?
Sample Code to Reproduce
#include <stdio.h>
#define MAXC 100 /* if you need a constant, #defien one (or more) */
int main (int argc, char* argv[]) {
if (argc < 2) { /* validate one argument give for filename */
fputs ("error: too few arguments.\n", stderr);
return 1;
}
char buf[MAXC] = "", c;
size_t n = 0;
FILE* fp = fopen (argv[1], "r");
if (fp == NULL) { /* validate file open for reading */
perror ("fopen-argv[1]"); /* on failure, perror() tells why */
return 1;
}
/* while buf not full (saving 1-char for \0), read char */
while (n + 1 < MAXC && (c = fgetc(fp)) != EOF)
buf[n++] = c; /* assign char to next element in buf */
buf[n] = 0; /* nul-terminate buf */
puts (buf); /* output result */
fclose(fp);
}
Expected behavior
All functions, especially from the same standard header stdio.h
should have consistent highlight applied.