C Basics
Validate Student Name
Accept a name and check if it contains only alphabetical characters.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Accept a name and check if it contains only alphabetical characters.
#include <stdio.h>
int main() {
char studentname[100];
int valid;
printf("Enter your name\n");
scanf("%s", studentname);
for (int i = 0; studentname[i] != '\0'; i++) {
if ((studentname[i] >= 'A' && studentname[i] <= 'Z') ||
(studentname[i] >= 'a' && studentname[i] <= 'z')) {
valid = 1;
} else {
valid = 0;
}
}
if (valid == 1) {
printf("your name is %s\n", studentname);
} else {
printf("Invalid name");
}
return 0;
}
Rahul
your name is Rahul