-
Notifications
You must be signed in to change notification settings - Fork 0
/
removedigits.cpp
executable file
·52 lines (51 loc) · 1.16 KB
/
removedigits.cpp
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
#include "stdafx.h"
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
void removeDigits(char *c);
struct test {
char input[20];
char output[20];
} testDB[12] = {
{"ABC123","ABC"},
{"12a34b56c","abc"},
{"1Ab C2","Ab C"},
{"123",""},
{"",""},
{"a1B2c","aBc"},
{"a b c","a b c"},
{"!@#$","!@#$"},
{"A!1@2b","A!@b"},
{" "," "},
{"1a2b345CDef&8(&*","abCDef&(&*"},
{NULL,NULL}
};
void testCases()
{
for(int i=0; i<12; i++)
{
removeDigits(testDB[i].input);
if(strcmp(testDB[i].input, testDB[i].output) == 0) printf("PASSED\n"); else printf("FAILED\n");
}
}
void removeDigits(char *input_str)
{
int i,read=0,write=0;//i:index ptr;read:read variable; write: write variable
for(read=0;input_str[read]!='\0';)
{
if(input_str[read]>='0'&&input_str[read]<='9')
read++;
else
{
input_str[write]=input_str[read];
read++;
write++;
}
}
input_str[write]='\0';
}
int _tmain(int argc, _TCHAR* argv[])
{
testCases();
return 0;
}