fseek() can be done on all streams - binary mode for binary streams (which the keyboard stream usually is for me), or in text mode, for text streams.
This is according to K&R 2nd Edition, not me.
Try this, and try to overstuff the buffer as much as you want.
Code:
/* Password.c Alpha ver. 1.02 by Adak */
#include <stdio.h>
#include <conio.h> /* for getch() */
#define MaxChars 20
char c;
char Usrname[MaxChars] = { '\0' };
char Passwrd[MaxChars] = { '\0' };
int main() {
int j, i = 0;
printf("\n\n Enter Username: ");
fgets(Usrname, MaxChars, stdin);
printf("\n Enter Password:");
putchar(' ');
while((c = getch()) != 13) { /* '\n' doesn't work here */
if (c > 31 && i < MaxChars - 1) {
putchar('*');
Passwrd[i++] = c;
}else {
if ((i > 0) && i -1 < (MaxChars - 1) && c == 8) {
putchar(c);
putchar(32);
putchar(c);
Passwrd[--i] = 32;
}
}
}
Passwrd[i] = '\0';
/* display it */
printf("\n\n Username: %s", Usrname);
printf("\n Password: %s", Passwrd);
printf("\n\n\t\t Program Complete, Please Press Enter ");
fseek(stdin, 0, SEEK_END);
c = getchar();
return(0);
}