If I make a program that asks you a name, how can i limit your inputted letters to ,say, 5 letters only?
You could limit the length of the string read in to five characters quite easily, but that doesn't prevent the user from typing more than that.
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
char name[6], *p;
int c;
printf("Enter your name: ");
fgets(name, sizeof(name), stdin);
if((p = strrchr(name, '\n'))) *p = 0;
while((c = getchar()) != '\n' && c != EOF);
printf("Hello, %s!", name);
return 0;
}