# How to display palindromes in a given randomized letters

Closed
gealon2024 Posts 7 Registration date Thursday October 3, 2013 Status Member Last seen April 30, 2014 - Oct 11, 2013 at 08:41 AM
BunoCS Posts 15477 Registration date Monday July 11, 2005 Status Moderator Last seen May 30, 2024 - Oct 12, 2013 at 07:14 AM
hello everyone, can anybody help me how to count and display the palindromes
in this randomized letters:

this is my program but it only prints randomized letters and can't count the palindromes words and display it:

`#include <stdio.h>#include <string.h>#include <stdlib.h>int max=0; int copy(char *str,int n);int rev(char *s);int palind(char *s);main(){    int x;    int y[50];    int i=0;    clrscr();    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    for(i=0; i<200; i++){        srand(time(NULL));        for(i=0;i<=200;i++){            x =rand()%26+97;            y[i] = x%26+97;            printf("%2c", x);            i++;        }    }    printf("\n\nThe PALINDROMES are:\n");    palind(x);     printf("The number of Palindrome is %d",max);     getchar(); }int copy(char *str,int n) {     char *st;     int i,q;     st=malloc(sizeof(char)*n);     for(i=0;i<=n;i++){         st[i]=str[i];     }     st[n+1]='\0';     x=strlen(st);    if(q>=3&&st[0]!=' '){        printf("%s\n",st);        max++;    }} int rev(char *s) {     int i,k,r,len;     len=strlen(s);     for(i=len-1;i>0;i--){         k=0;         r=i;         while(k < r && s[k] == s[r]){             k++;             r--;         }         if(k >= r){             copy(s,i);         }     } }  int palind(char *s) {     int i,len;     len=strlen(s);     for(i=0;i<len;i++){         rev(&s[i]);     }     getch();}`
Related:

## 2 responses

BunoCS Posts 15477 Registration date Monday July 11, 2005 Status Moderator Last seen May 30, 2024 1,534
Oct 12, 2013 at 07:05 AM
Hello,
We already help you to discover palindromes and to count them.
What is the problem, now?

Note: I've edited your message to fix code tags.
BunoCS Posts 15477 Registration date Monday July 11, 2005 Status Moderator Last seen May 30, 2024 1,534
Oct 12, 2013 at 07:14 AM
I don't understand why you are doing 7 times the same for loop...
Moreover,
`for(i=0; i<200; i++){srand(time(NULL));for(i=0;i<=200;i++){x =rand()%26+97;y[i] = x%26+97;printf("%2c", x);i++;}}`
- you're using the same i in outer and inner loop -> dangerous.
- y[i]: i goes from 0 to 200. But, y is an array of 50 int -> it crashes

What do you want to do?

@+
Buno, Modo CS-CCM
The urgent is done, the impossible is underway. For miracles, envisage a time ...