Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <Windows.h>
- char *process(char*);
- void main()
- {
- char a[100], b[100], *r;
- printf("Enter the string to check if it is a palindrome\n");
- gets(a);
- r = process(a);
- strcpy(b,a);
- strrev(b);
- if (strcmp(a,b) == 0)
- {
- printf("%s string is a palindrome.\n",a);
- free(r);
- }
- else
- {
- printf("Entered string is not a palindrome.\n");
- free(r);
- }
- getch();
- }
- char *process(char *a) {
- int length, c, d;
- char *start;
- c = d = 0;
- length = strlen(a);
- start = (char*)malloc(length+1);
- if (start == NULL)
- exit(EXIT_FAILURE);
- while (*(a+c) != '\0') {
- if (*(a+c) == ' ') {
- int temp = c + 1;
- if (*(a+temp) != '\0') {
- while (*(a+temp) == ' ' && *(a+temp) != '\0') {
- if (*(a+temp) == ' ') {
- c++;
- }
- temp++;
- }
- }
- }
- *(start+d) = *(a+c);
- c++;
- d++;
- }
- *(start+d)= '\0';
- return start;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement