Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <Windows.h>
  6.  
  7. char *process(char*);
  8.  
  9. void main()
  10. {
  11. char a[100], b[100], *r;
  12.  
  13. printf("Enter the string to check if it is a palindrome\n");
  14. gets(a);
  15. r = process(a);
  16.  
  17. strcpy(b,a);
  18. strrev(b);
  19.  
  20. if (strcmp(a,b) == 0)
  21. {
  22. printf("%s string is a palindrome.\n",a);
  23. free(r);
  24. }
  25. else
  26. {
  27. printf("Entered string is not a palindrome.\n");
  28. free(r);
  29. }
  30.  
  31. getch();
  32. }
  33.  
  34. char *process(char *a) {
  35. int length, c, d;
  36. char *start;
  37.  
  38. c = d = 0;
  39.  
  40. length = strlen(a);
  41.  
  42. start = (char*)malloc(length+1);
  43.  
  44. if (start == NULL)
  45. exit(EXIT_FAILURE);
  46.  
  47. while (*(a+c) != '\0') {
  48. if (*(a+c) == ' ') {
  49. int temp = c + 1;
  50. if (*(a+temp) != '\0') {
  51. while (*(a+temp) == ' ' && *(a+temp) != '\0') {
  52. if (*(a+temp) == ' ') {
  53. c++;
  54. }
  55. temp++;
  56. }
  57. }
  58. }
  59. *(start+d) = *(a+c);
  60. c++;
  61. d++;
  62. }
  63. *(start+d)= '\0';
  64.  
  65. return start;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement