-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm-test.cpp
More file actions
42 lines (36 loc) · 859 Bytes
/
Copy pathm-test.cpp
File metadata and controls
42 lines (36 loc) · 859 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
36
37
38
39
40
41
42
//Finding Memory Leaks Using mtrace 1/3
/*
*m-test.cpp: This is a simple C++ program to demonstrate memory leak problem.
*Link: http://munir.wordpress.com/2006/08/05/finding-memory-leaks-using-mtrace/
*Author: Munir Usman - http://munir.wordpress.com
*/
#include <iostream>
#include <cstdlib>
#define SIZE 16
using namespace std;
bool isPalindrome(char *);
int main()
{
char *str;
while(true)
{
str = (char *)malloc(SIZE);
cout << "Enter string to check Palindrome or quit to exit: ";
cin >> str;
if(strcmp(str, "quit") == 0)
break;
if(isPalindrome(str))
cout << str << " is a Palindrome." << endl;
else
cout << str << " is NOT a Palindrome." << endl;
}
return 0;
}
bool isPalindrome(char *str)
{
int str_len = strlen(str);
for(int i = 0; i < str_len/2; i++)
if(str[i] != str[str_len-i-1])
return false;
return true;
}