-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackstringcheck.cpp
More file actions
67 lines (66 loc) · 1.09 KB
/
stackstringcheck.cpp
File metadata and controls
67 lines (66 loc) · 1.09 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
using namespace std;
struct stack
{
char *s;
int top;
int size;
void init(int n)
{
size=n;
s=new char[size];
top=-1;
}
void push(char x)
{
if(top==size-1)return;
s[++top]=x;
}
char pop()
{
if(top==-1)return'\0';
return s[top--];
}
};
bool isnotalpha(char c)
{return !((c>='A'&&c<='Z')||(c>='a'&&c<='z'));}//return (!true)=false if c is alpha and (!false)=ture if c is not alpha
void nonalphacheck(stack &s1)
{
bool found =false;
while(s1.top!=-1)
{
char c=s1.pop();
if(isnotalpha(c))
{
cout<<"Non-alphabetical character found: '" << c << "'\n";
found = true;
}
}
if(!found)
cout<<"all characters are alphabetical";
}
int getLength(char a[])
{
int i=0;
while(a[i]!='\0')
i++;
return i;
}
int main()
{
char a[100];
fgets(a,100,stdin);
int len=getLength(a);
if (a[len - 1] == '\n')
{
a[len - 1] = '\0';
len--;
}
stack s1;
s1.init(len);
for(int i=0;i<len;i++)
{
s1.push(a[i]);
}
nonalphacheck(s1);
}