extracting spaces from char array string

I cant figure how to extract spaces from char array. I can extract double quotes and single quote I put the \ char before quote and single quotes and the program runs fine. I tried using ' ' to represent space and i tried '/ ' not sure what denotes spaces. The function of program is to verify a palindrome recursively while extracting punctuation.
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdafx.h"
#include <iostream>

bool palindrome(char[], int);

int main()
{
	using namespace std;
	bool status;
	int siz,i;
	char strarry[20];
	siz = 0;

	cout << " enter string" << endl;
	cin >> strarry;

	for (i = 0; strarry[i] != '\0'; i++)
		++siz;

	status = palindrome(strarry, siz);
	if (status)
		cout << " the string is a palindrome" << endl;
	else
		cout << "not a palindrome" << endl;

	cin.clear();
	cin.ignore(255, '/n');
	cin.get();


	return 0;
}

bool palindrome(char arry[], int size)
{
	int i, l;
	static bool search = false;
	static bool match = false;
	static bool found = false;
	static int n = 0;
	int end = size - 1;
	
	if (search != true){
		for (i = 0; i <= end; i++){
		if ((arry[i] == ' ') || (arry[i] == '\'') || (arry[i] == '\"')){
				if ((end - i) >= 1){
					for (l = i; l <= end; l++)
						arry[l] = arry[l + 1];
					--end;
					size = end;
				}
				else{
					size= end - 1;
				}
				found = true;
		}//end if
		}// end for
		if (found == false)
			size = end;
		search = true;
	}//end if

	

	if (((n - size) <= 1) && match )
		return true;
	else{
		if (arry[n] == arry[size]){
			++n;
			match = true;
			return palindrome(arry, size - 1);
		}
		else{
			match = false;
			return false;
		}//end else

	}// end else


} 
Last edited on
Topic archived. No new replies allowed.