Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,987 questions

51,931 answers

573 users

How to print the palindrome words in a string with C

3 Answers

0 votes
#include <stdio.h>
#include <string.h>

void PrintPalindromeWords(char str[], char* delimiter) {
    char* word = strtok(str, delimiter);

    while (word != NULL) {
        int result = _stricmp(word, _strrev(_strdup(word)));
        if (result == 0 && strlen(word) >= 3)
            puts(word);
        word = strtok(NULL, delimiter);
    }
}

int main(void)
{
    char s[] = "c madam c++ civic java pytyp dart";

    PrintPalindromeWords(s, " ");

    return 0;
}





/*
run:

madam
civic
pytyp

*/

 



answered Nov 12, 2022 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void PrintPalindromeWords(char str[], char* delimiter) {
    char* word = strtok(str, delimiter);

    while (word != NULL) {
        char* p = _strdup(word);
        int result = _stricmp(word, _strrev(p));
        free(p);
        if (result == 0 && strlen(word) >= 3) {
            puts(word);
        }
        word = strtok(NULL, delimiter);
    }
}

int main(void)
{
    char s[] = "c madam c++ civic java pytyp dart";

    PrintPalindromeWords(s, " ");

    return 0;
}





/*
run:

madam
civic
pytyp

*/

 



answered Nov 12, 2022 by avibootz
edited Dec 28, 2023 by avibootz
0 votes
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char string[] = "c madam c++ civic java pytyp dart";
    char delimiters[] = " ";

    char* p = strtok(string, delimiters);

    while (p) {
        char* word = _strdup(p);
        if (strcmp(word, _strrev(p)) == 0 && strlen(p) >= 3) {
            puts(p);
        }
        free(word);

        p = strtok(NULL, delimiters);
    }


    return 0;
}




/*
run:

madam
civic
pytyp

*/

 



answered Dec 28, 2023 by avibootz

Related questions

1 answer 126 views
1 answer 124 views
2 answers 121 views
2 answers 130 views
1 answer 86 views
2 answers 134 views
1 answer 84 views
...