Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / task1.cpp
blob: 1698c33d5380f8690cc4132e2367099cf14b8b68 (plain) (blame)
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
#include <iostream>
using namespace std;

bool isDigit(char ch)
{
	return ch >= '0' && ch <= '9';
}
int countDigits(const char* str)
{
	//int len = strlen(str);
	//int count = 0;
	//for (int i = 0; i < len; i++)
	//{
	//	if (isDigit(str[i]))
	//		count++;
	//}

	int count = 0;
	while (*str != '\0')
	{
		if (isDigit(*str))
			count++;
		str++;
	}
	return count;
}

void removeDigits(const char* str, char* resultStr)
{
	while (*str != '\0')
	{
		if (!isDigit(*str))
		{
			*resultStr = *str;
			resultStr++;
		}
		str++;
	}
	*resultStr = '\0';
}
int main()
{
	const char* str = "hello friends 123 , how are you? 343. Fine!";

	int len = strlen(str) - countDigits(str);

	char* resultStr = new char[len + 1];

	removeDigits(str, resultStr);

	cout << resultStr << endl;

	delete[] resultStr;
}