-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab4.cpp
More file actions
35 lines (29 loc) · 771 Bytes
/
Lab4.cpp
File metadata and controls
35 lines (29 loc) · 771 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
#include <iostream>
#include <string>
using namespace std;
int main() {
string identifier;
int flag = 1, i = 1;
cout << "Enter an identifier: ";
getline(cin, identifier);
// Check if first character is a letter or underscore
if (isalpha(identifier[0]) || identifier[0] == '_')
flag = 1;
else {
flag = 0;
}
// Check remaining characters
while (i < identifier.length()) {
if (!isalnum(identifier[i]) && identifier[i] != '_') {
flag = 0;
break;
}
i++;
}
if (flag == 1)
cout << "It is a valid identifier" << endl;
else
cout << "It is not a valid identifier" << endl;
cout << "\nCompiled by : Subodh Ghimire" << endl;
return 0;
}