Given a series of characters from stdin, print their squared integer ASCII counterparts This program in essence is extremely simple, however, it can be written in many different ways. I'm a beginner at C and I've written it in 5 different variations (mostly differing in the use of getchar over scanf, while over do while loops..). 

Apart from readability and/or maintainability, is there any difference between these 5 code blocks (such as perhaps performance or efficiency, if we disregard the use of getchar over scanf)?

unsigned char d;



while (1)
    while(scanf("%c", &amp;d), d != '\n') {
        printf("%d\n", d * d);
    }  

do {
    scanf(" %c", &amp;d);
    printf("%d\n", d * d);
} while (1);

while (1)
    while((d = getchar()) != '\n') { //could also be written as while(d = getchar(), d != '\n')
        printf("%d\n", d * d);
    }

while ((d = getchar())) {
    if(d == '\n')
        continue;
    printf("%d\n", d * d);
}

do {
    d = getchar();
    if(d == '\n')
        continue;
    printf("%d\n", d * d);
} while (1);
while (1)
    while(scanf("%c", &amp;d), d != '\n') {
        printf("%d\n", d * d);
    }



It's better to consistently add braces around the body of statements like while and if.
A common mistake is to write something like this:

while (1)
    while(scanf("%c", &amp;d), d != '\n') {
        printf("%d\n", d * d);
    }
    printf("...");


This may mislead a reader to think that the last printf is part of the outer loop, when it isn't. Just put the braces around the body always.

Another negative point in this version is having two statements inside the inner while. This is not easy to read. It's better to write in a way that there is no more than one statement per line. More generally, I recommend to avoid the , operator entirely.

The same point applies to this line in the 3rd version:


while((d = getchar()) != '\n') {



That is, there is an assignment within the conditional statement.
Avoid such "clever" writing style.
Stick to one statement per line.

And one more variation of the same issue, in the 4th version:


while ((d = getchar())) {