Finding a reversed words in a given string using C program










-1















Actually I have been searching for more than 1 week to find a solution for finding a reversed words in a given string using C. My question is, I have been given a string like this "bakelovekac". Here I have a reversed word of "ake" as "eka" in a string. Now I need to find out this reversed word in a given string and print it. How can it be done? Thanks in advance!










share|improve this question






















  • Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

    – Hoblovski
    Nov 15 '18 at 1:41











  • There is no time limit

    – Dhans
    Nov 15 '18 at 2:10











  • is ake a word? is it just any series of characters or does it have to be a real word?

    – Bwebb
    Nov 15 '18 at 2:18











  • @Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

    – Dhans
    Nov 15 '18 at 2:22











  • any limit on the size of the original word?

    – Bwebb
    Nov 15 '18 at 2:40















-1















Actually I have been searching for more than 1 week to find a solution for finding a reversed words in a given string using C. My question is, I have been given a string like this "bakelovekac". Here I have a reversed word of "ake" as "eka" in a string. Now I need to find out this reversed word in a given string and print it. How can it be done? Thanks in advance!










share|improve this question






















  • Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

    – Hoblovski
    Nov 15 '18 at 1:41











  • There is no time limit

    – Dhans
    Nov 15 '18 at 2:10











  • is ake a word? is it just any series of characters or does it have to be a real word?

    – Bwebb
    Nov 15 '18 at 2:18











  • @Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

    – Dhans
    Nov 15 '18 at 2:22











  • any limit on the size of the original word?

    – Bwebb
    Nov 15 '18 at 2:40













-1












-1








-1


1






Actually I have been searching for more than 1 week to find a solution for finding a reversed words in a given string using C. My question is, I have been given a string like this "bakelovekac". Here I have a reversed word of "ake" as "eka" in a string. Now I need to find out this reversed word in a given string and print it. How can it be done? Thanks in advance!










share|improve this question














Actually I have been searching for more than 1 week to find a solution for finding a reversed words in a given string using C. My question is, I have been given a string like this "bakelovekac". Here I have a reversed word of "ake" as "eka" in a string. Now I need to find out this reversed word in a given string and print it. How can it be done? Thanks in advance!







c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 1:36









DhansDhans

1067




1067












  • Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

    – Hoblovski
    Nov 15 '18 at 1:41











  • There is no time limit

    – Dhans
    Nov 15 '18 at 2:10











  • is ake a word? is it just any series of characters or does it have to be a real word?

    – Bwebb
    Nov 15 '18 at 2:18











  • @Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

    – Dhans
    Nov 15 '18 at 2:22











  • any limit on the size of the original word?

    – Bwebb
    Nov 15 '18 at 2:40

















  • Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

    – Hoblovski
    Nov 15 '18 at 1:41











  • There is no time limit

    – Dhans
    Nov 15 '18 at 2:10











  • is ake a word? is it just any series of characters or does it have to be a real word?

    – Bwebb
    Nov 15 '18 at 2:18











  • @Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

    – Dhans
    Nov 15 '18 at 2:22











  • any limit on the size of the original word?

    – Bwebb
    Nov 15 '18 at 2:40
















Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

– Hoblovski
Nov 15 '18 at 1:41





Seems an ACM or OI problem... What's the range of string length? What's the time limit? If there's no restriction on time, you may just use a stupid brute force; otherwise you need some clever hash trick or dynamic programming I guess.

– Hoblovski
Nov 15 '18 at 1:41













There is no time limit

– Dhans
Nov 15 '18 at 2:10





There is no time limit

– Dhans
Nov 15 '18 at 2:10













is ake a word? is it just any series of characters or does it have to be a real word?

– Bwebb
Nov 15 '18 at 2:18





is ake a word? is it just any series of characters or does it have to be a real word?

– Bwebb
Nov 15 '18 at 2:18













@Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

– Dhans
Nov 15 '18 at 2:22





@Bwebb No it doesn't need to be a real word. Just being a series of characters is enough.

– Dhans
Nov 15 '18 at 2:22













any limit on the size of the original word?

– Bwebb
Nov 15 '18 at 2:40





any limit on the size of the original word?

– Bwebb
Nov 15 '18 at 2:40












2 Answers
2






active

oldest

votes


















0














A basic approach would be to iterate over all the characters of the string and for each character check if it is being repeated, if yes then check for the presence of a possible reverse string.



A crude code for above approach would look something like this:



#include <stdio.h>

void checkForRevWord(char *str, char *rev)
int length = 0;
while(1)
if(str >= rev)
break;
if(*str != *rev)
break;
length++;
str++;
rev--;

if(length > 1)
while(length--)
printf("%c", *(rev+length+1));
printf("n");

return;


int main()

char *inputStr = "bakelovekac";
char *cur = inputStr;
char *tmp;

while(*cur != '')
tmp = cur+1;
/* find if current char gets repeated in the input string*/
while(*tmp != '')
if(*tmp == *cur)
checkForRevWord(cur, tmp);

tmp++;

cur++;







share|improve this answer






























    0














    Go through this program



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

    int main()

    char text[50]; //this character array to store string
    int len,i;
    printf("Enter a textn");
    scanf("%[^n]s",text);//getting the user input with spaces until the end of the line
    len=strlen(text);//getting the length of the array and assigning it the len variable
    for(i=len-1;i>=0;i--)

    printf("%c",text[i]); //printing the text from backwards

    return 0;



    thank you.






    share|improve this answer























    • This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

      – Bwebb
      Nov 15 '18 at 20:19










    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%2f53311240%2ffinding-a-reversed-words-in-a-given-string-using-c-program%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    A basic approach would be to iterate over all the characters of the string and for each character check if it is being repeated, if yes then check for the presence of a possible reverse string.



    A crude code for above approach would look something like this:



    #include <stdio.h>

    void checkForRevWord(char *str, char *rev)
    int length = 0;
    while(1)
    if(str >= rev)
    break;
    if(*str != *rev)
    break;
    length++;
    str++;
    rev--;

    if(length > 1)
    while(length--)
    printf("%c", *(rev+length+1));
    printf("n");

    return;


    int main()

    char *inputStr = "bakelovekac";
    char *cur = inputStr;
    char *tmp;

    while(*cur != '')
    tmp = cur+1;
    /* find if current char gets repeated in the input string*/
    while(*tmp != '')
    if(*tmp == *cur)
    checkForRevWord(cur, tmp);

    tmp++;

    cur++;







    share|improve this answer



























      0














      A basic approach would be to iterate over all the characters of the string and for each character check if it is being repeated, if yes then check for the presence of a possible reverse string.



      A crude code for above approach would look something like this:



      #include <stdio.h>

      void checkForRevWord(char *str, char *rev)
      int length = 0;
      while(1)
      if(str >= rev)
      break;
      if(*str != *rev)
      break;
      length++;
      str++;
      rev--;

      if(length > 1)
      while(length--)
      printf("%c", *(rev+length+1));
      printf("n");

      return;


      int main()

      char *inputStr = "bakelovekac";
      char *cur = inputStr;
      char *tmp;

      while(*cur != '')
      tmp = cur+1;
      /* find if current char gets repeated in the input string*/
      while(*tmp != '')
      if(*tmp == *cur)
      checkForRevWord(cur, tmp);

      tmp++;

      cur++;







      share|improve this answer

























        0












        0








        0







        A basic approach would be to iterate over all the characters of the string and for each character check if it is being repeated, if yes then check for the presence of a possible reverse string.



        A crude code for above approach would look something like this:



        #include <stdio.h>

        void checkForRevWord(char *str, char *rev)
        int length = 0;
        while(1)
        if(str >= rev)
        break;
        if(*str != *rev)
        break;
        length++;
        str++;
        rev--;

        if(length > 1)
        while(length--)
        printf("%c", *(rev+length+1));
        printf("n");

        return;


        int main()

        char *inputStr = "bakelovekac";
        char *cur = inputStr;
        char *tmp;

        while(*cur != '')
        tmp = cur+1;
        /* find if current char gets repeated in the input string*/
        while(*tmp != '')
        if(*tmp == *cur)
        checkForRevWord(cur, tmp);

        tmp++;

        cur++;







        share|improve this answer













        A basic approach would be to iterate over all the characters of the string and for each character check if it is being repeated, if yes then check for the presence of a possible reverse string.



        A crude code for above approach would look something like this:



        #include <stdio.h>

        void checkForRevWord(char *str, char *rev)
        int length = 0;
        while(1)
        if(str >= rev)
        break;
        if(*str != *rev)
        break;
        length++;
        str++;
        rev--;

        if(length > 1)
        while(length--)
        printf("%c", *(rev+length+1));
        printf("n");

        return;


        int main()

        char *inputStr = "bakelovekac";
        char *cur = inputStr;
        char *tmp;

        while(*cur != '')
        tmp = cur+1;
        /* find if current char gets repeated in the input string*/
        while(*tmp != '')
        if(*tmp == *cur)
        checkForRevWord(cur, tmp);

        tmp++;

        cur++;








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 4:44









        SandeepSandeep

        647311




        647311























            0














            Go through this program



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

            int main()

            char text[50]; //this character array to store string
            int len,i;
            printf("Enter a textn");
            scanf("%[^n]s",text);//getting the user input with spaces until the end of the line
            len=strlen(text);//getting the length of the array and assigning it the len variable
            for(i=len-1;i>=0;i--)

            printf("%c",text[i]); //printing the text from backwards

            return 0;



            thank you.






            share|improve this answer























            • This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

              – Bwebb
              Nov 15 '18 at 20:19















            0














            Go through this program



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

            int main()

            char text[50]; //this character array to store string
            int len,i;
            printf("Enter a textn");
            scanf("%[^n]s",text);//getting the user input with spaces until the end of the line
            len=strlen(text);//getting the length of the array and assigning it the len variable
            for(i=len-1;i>=0;i--)

            printf("%c",text[i]); //printing the text from backwards

            return 0;



            thank you.






            share|improve this answer























            • This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

              – Bwebb
              Nov 15 '18 at 20:19













            0












            0








            0







            Go through this program



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

            int main()

            char text[50]; //this character array to store string
            int len,i;
            printf("Enter a textn");
            scanf("%[^n]s",text);//getting the user input with spaces until the end of the line
            len=strlen(text);//getting the length of the array and assigning it the len variable
            for(i=len-1;i>=0;i--)

            printf("%c",text[i]); //printing the text from backwards

            return 0;



            thank you.






            share|improve this answer













            Go through this program



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

            int main()

            char text[50]; //this character array to store string
            int len,i;
            printf("Enter a textn");
            scanf("%[^n]s",text);//getting the user input with spaces until the end of the line
            len=strlen(text);//getting the length of the array and assigning it the len variable
            for(i=len-1;i>=0;i--)

            printf("%c",text[i]); //printing the text from backwards

            return 0;



            thank you.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 4:55









            Jayaraj RohanJayaraj Rohan

            164




            164












            • This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

              – Bwebb
              Nov 15 '18 at 20:19

















            • This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

              – Bwebb
              Nov 15 '18 at 20:19
















            This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

            – Bwebb
            Nov 15 '18 at 20:19





            This seems to not address the OPs question about finding a sub string inside the string. I will let him decide though.

            – Bwebb
            Nov 15 '18 at 20:19

















            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%2f53311240%2ffinding-a-reversed-words-in-a-given-string-using-c-program%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線