c_idioms

scanf skip rest of the line

while (getchar() != '\n')
    ;

scanf skip blanks

while ((ch = getchar()) == ' ')
    ;

length of an array

int len = sizeof(a)/sizeof(a[0]);

linked list traversal idiom

Visit nodes in a linked list, using a pointer variable p to keep track of the “current” node.

for (p = first; p != NULL; p = p->next)

idiom for finding the length of an array

sizeof(a) / sizeof(a[10]);

search for the null character at the end of a string

while (*s++) {
    ;
}
/* s points to just past null char */
while (*s) {
    s++;
}
/* s points to null char */

copy string from one place to another

while (*p++ = *s2++) {
    ; /* loop terminates after assignment */
}

credit

c_programming_a_modern_approach c

backlinks