find palindromes in the row and display them












0















A string consisting of words, no longer than 100 characters, is supplied. Words consist of Latin characters and are separated by a single space. It is necessary to output to the standard output stream a string containing only the words palindromes.
The source data must be read into memory as a whole and all manipulations must be carried out in memory, the result obtained in memory and then printed.



#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check(char str)
{
int i, length;

length = strlen(str);

for (i = 0; i < length; i++)
if (str[i] != str[(length - 1) - i]) return 0;
return 1;
}

int main(void)
{
char str[100];
char* t;

gets(str);
t = strtok(str, " ");


while (t != NULL) {
if (check(t) == 1) {
printf("%s ", t);

}

t = strtok(NULL, " ");
}
_getch();
return 0;
}


this is my code (it fails the tests)
Please help me fix the code










share|improve this question




















  • 1





    Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

    – Some programmer dude
    Nov 26 '18 at 13:38











  • As for your problem, this might be a good time to learn how to debug your programs.

    – Some programmer dude
    Nov 26 '18 at 13:40











  • Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

    – Some programmer dude
    Nov 26 '18 at 13:44













  • I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

    – Notoriuss
    Nov 26 '18 at 13:54











  • Why for (i = 0; i < length? length/2 seems enough.

    – Paul Ogilvie
    Nov 26 '18 at 14:01
















0















A string consisting of words, no longer than 100 characters, is supplied. Words consist of Latin characters and are separated by a single space. It is necessary to output to the standard output stream a string containing only the words palindromes.
The source data must be read into memory as a whole and all manipulations must be carried out in memory, the result obtained in memory and then printed.



#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check(char str)
{
int i, length;

length = strlen(str);

for (i = 0; i < length; i++)
if (str[i] != str[(length - 1) - i]) return 0;
return 1;
}

int main(void)
{
char str[100];
char* t;

gets(str);
t = strtok(str, " ");


while (t != NULL) {
if (check(t) == 1) {
printf("%s ", t);

}

t = strtok(NULL, " ");
}
_getch();
return 0;
}


this is my code (it fails the tests)
Please help me fix the code










share|improve this question




















  • 1





    Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

    – Some programmer dude
    Nov 26 '18 at 13:38











  • As for your problem, this might be a good time to learn how to debug your programs.

    – Some programmer dude
    Nov 26 '18 at 13:40











  • Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

    – Some programmer dude
    Nov 26 '18 at 13:44













  • I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

    – Notoriuss
    Nov 26 '18 at 13:54











  • Why for (i = 0; i < length? length/2 seems enough.

    – Paul Ogilvie
    Nov 26 '18 at 14:01














0












0








0








A string consisting of words, no longer than 100 characters, is supplied. Words consist of Latin characters and are separated by a single space. It is necessary to output to the standard output stream a string containing only the words palindromes.
The source data must be read into memory as a whole and all manipulations must be carried out in memory, the result obtained in memory and then printed.



#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check(char str)
{
int i, length;

length = strlen(str);

for (i = 0; i < length; i++)
if (str[i] != str[(length - 1) - i]) return 0;
return 1;
}

int main(void)
{
char str[100];
char* t;

gets(str);
t = strtok(str, " ");


while (t != NULL) {
if (check(t) == 1) {
printf("%s ", t);

}

t = strtok(NULL, " ");
}
_getch();
return 0;
}


this is my code (it fails the tests)
Please help me fix the code










share|improve this question
















A string consisting of words, no longer than 100 characters, is supplied. Words consist of Latin characters and are separated by a single space. It is necessary to output to the standard output stream a string containing only the words palindromes.
The source data must be read into memory as a whole and all manipulations must be carried out in memory, the result obtained in memory and then printed.



#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check(char str)
{
int i, length;

length = strlen(str);

for (i = 0; i < length; i++)
if (str[i] != str[(length - 1) - i]) return 0;
return 1;
}

int main(void)
{
char str[100];
char* t;

gets(str);
t = strtok(str, " ");


while (t != NULL) {
if (check(t) == 1) {
printf("%s ", t);

}

t = strtok(NULL, " ");
}
_getch();
return 0;
}


this is my code (it fails the tests)
Please help me fix the code







c visual-studio palindrome






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 16:25









Dominique

1,96941741




1,96941741










asked Nov 26 '18 at 13:36









NotoriussNotoriuss

11




11








  • 1





    Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

    – Some programmer dude
    Nov 26 '18 at 13:38











  • As for your problem, this might be a good time to learn how to debug your programs.

    – Some programmer dude
    Nov 26 '18 at 13:40











  • Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

    – Some programmer dude
    Nov 26 '18 at 13:44













  • I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

    – Notoriuss
    Nov 26 '18 at 13:54











  • Why for (i = 0; i < length? length/2 seems enough.

    – Paul Ogilvie
    Nov 26 '18 at 14:01














  • 1





    Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

    – Some programmer dude
    Nov 26 '18 at 13:38











  • As for your problem, this might be a good time to learn how to debug your programs.

    – Some programmer dude
    Nov 26 '18 at 13:40











  • Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

    – Some programmer dude
    Nov 26 '18 at 13:44













  • I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

    – Notoriuss
    Nov 26 '18 at 13:54











  • Why for (i = 0; i < length? length/2 seems enough.

    – Paul Ogilvie
    Nov 26 '18 at 14:01








1




1





Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

– Some programmer dude
Nov 26 '18 at 13:38





Never ever use gets! It's a dangerous function that have even been removed from the C standard. Use e.g. fgets instead.

– Some programmer dude
Nov 26 '18 at 13:38













As for your problem, this might be a good time to learn how to debug your programs.

– Some programmer dude
Nov 26 '18 at 13:40





As for your problem, this might be a good time to learn how to debug your programs.

– Some programmer dude
Nov 26 '18 at 13:40













Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

– Some programmer dude
Nov 26 '18 at 13:44







Lastly, please read about how to ask good questions, as well as this question checklist. Then edit your question to improve it.

– Some programmer dude
Nov 26 '18 at 13:44















I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

– Notoriuss
Nov 26 '18 at 13:54





I don't know what else you can change (thanks for the fgets I will definitely change it), who can email me the corrected code please

– Notoriuss
Nov 26 '18 at 13:54













Why for (i = 0; i < length? length/2 seems enough.

– Paul Ogilvie
Nov 26 '18 at 14:01





Why for (i = 0; i < length? length/2 seems enough.

– Paul Ogilvie
Nov 26 '18 at 14:01












1 Answer
1






active

oldest

votes


















0















  1. Instead of fgets use function getline(&buffer, &size, stdion) for example.

  2. Your for loop in the check function works fine but resolve another problem, than that you expected.


  3. Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.






share|improve this answer
























  • this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

    – Notoriuss
    Nov 26 '18 at 16:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482322%2ffind-palindromes-in-the-row-and-display-them%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















  1. Instead of fgets use function getline(&buffer, &size, stdion) for example.

  2. Your for loop in the check function works fine but resolve another problem, than that you expected.


  3. Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.






share|improve this answer
























  • this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

    – Notoriuss
    Nov 26 '18 at 16:24
















0















  1. Instead of fgets use function getline(&buffer, &size, stdion) for example.

  2. Your for loop in the check function works fine but resolve another problem, than that you expected.


  3. Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.






share|improve this answer
























  • this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

    – Notoriuss
    Nov 26 '18 at 16:24














0












0








0








  1. Instead of fgets use function getline(&buffer, &size, stdion) for example.

  2. Your for loop in the check function works fine but resolve another problem, than that you expected.


  3. Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.






share|improve this answer














  1. Instead of fgets use function getline(&buffer, &size, stdion) for example.

  2. Your for loop in the check function works fine but resolve another problem, than that you expected.


  3. Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 15:33









alexzokalexzok

466




466













  • this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

    – Notoriuss
    Nov 26 '18 at 16:24



















  • this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

    – Notoriuss
    Nov 26 '18 at 16:24

















this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

– Notoriuss
Nov 26 '18 at 16:24





this code it works, try to enter any words of palindromes and it will output them if this is true (but for some reason my tests do not pass this code 0/16)

– Notoriuss
Nov 26 '18 at 16:24




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482322%2ffind-palindromes-in-the-row-and-display-them%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)