find palindromes in the row and display them
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
|
show 2 more comments
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
1
Never ever usegets
! 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
Whyfor (i = 0; i < length
?length/2
seems enough.
– Paul Ogilvie
Nov 26 '18 at 14:01
|
show 2 more comments
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
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
c visual-studio palindrome
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 usegets
! 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
Whyfor (i = 0; i < length
?length/2
seems enough.
– Paul Ogilvie
Nov 26 '18 at 14:01
|
show 2 more comments
1
Never ever usegets
! 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
Whyfor (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
|
show 2 more comments
1 Answer
1
active
oldest
votes
- Instead of
fgets
use functiongetline(&buffer, &size, stdion)
for example. - Your
for
loop in thecheck
function works fine but resolve another problem, than that you expected.
Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
- Instead of
fgets
use functiongetline(&buffer, &size, stdion)
for example. - Your
for
loop in thecheck
function works fine but resolve another problem, than that you expected.
Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.
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
add a comment |
- Instead of
fgets
use functiongetline(&buffer, &size, stdion)
for example. - Your
for
loop in thecheck
function works fine but resolve another problem, than that you expected.
Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.
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
add a comment |
- Instead of
fgets
use functiongetline(&buffer, &size, stdion)
for example. - Your
for
loop in thecheck
function works fine but resolve another problem, than that you expected.
Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.
- Instead of
fgets
use functiongetline(&buffer, &size, stdion)
for example. - Your
for
loop in thecheck
function works fine but resolve another problem, than that you expected.
Palindrome a word or group of words that is the same when you read it forwards from the beginning or backwards from the end.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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