-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject2_valid.c
More file actions
36 lines (28 loc) · 856 Bytes
/
project2_valid.c
File metadata and controls
36 lines (28 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Anisha Hossain Megha (U43189731)
// this program prompts the user to enter input and determines if the input is a valid or invalid.
#include <stdio.h>
#include <ctype.h>
int main(){
char user_input; // stores input by user
int validity = 1; // assigning validity
printf("Enter input:");
// validating the input
while((user_input = getchar()) != '\n'){
if (islower(user_input) || isdigit(user_input) || user_input == ' ' || user_input == '!' || user_input == '?' || user_input == '.'){
}
else if(isupper(user_input)){
validity = 0;
}
else{
validity = 0;
}
}
// showcasing whether it is valid or not
if(validity == 0){
printf("invalid");
}
else{
printf("valid");
}
return 0;
}