How to link the 2 functions












-1















What do i need to change that change_sequence_2() is able to get the info from tausche_2()?



void tausche_2 (char *c1, char *c2)
{
char temp;
temp = *c1;
*c1 = *c2;
*c2 = temp;
}

void change_sequence_2(char *F)
{
int i, j;
i = 0;
j = strlen(F) - 1;
while (i < j) {
tausche_2 (F, i, j);
i = i + 1;
j = j - 1;
}
}









share|improve this question

























  • tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

    – SPlatten
    Nov 22 '18 at 15:52











  • Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

    – Jabberwocky
    Nov 22 '18 at 15:58


















-1















What do i need to change that change_sequence_2() is able to get the info from tausche_2()?



void tausche_2 (char *c1, char *c2)
{
char temp;
temp = *c1;
*c1 = *c2;
*c2 = temp;
}

void change_sequence_2(char *F)
{
int i, j;
i = 0;
j = strlen(F) - 1;
while (i < j) {
tausche_2 (F, i, j);
i = i + 1;
j = j - 1;
}
}









share|improve this question

























  • tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

    – SPlatten
    Nov 22 '18 at 15:52











  • Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

    – Jabberwocky
    Nov 22 '18 at 15:58
















-1












-1








-1








What do i need to change that change_sequence_2() is able to get the info from tausche_2()?



void tausche_2 (char *c1, char *c2)
{
char temp;
temp = *c1;
*c1 = *c2;
*c2 = temp;
}

void change_sequence_2(char *F)
{
int i, j;
i = 0;
j = strlen(F) - 1;
while (i < j) {
tausche_2 (F, i, j);
i = i + 1;
j = j - 1;
}
}









share|improve this question
















What do i need to change that change_sequence_2() is able to get the info from tausche_2()?



void tausche_2 (char *c1, char *c2)
{
char temp;
temp = *c1;
*c1 = *c2;
*c2 = temp;
}

void change_sequence_2(char *F)
{
int i, j;
i = 0;
j = strlen(F) - 1;
while (i < j) {
tausche_2 (F, i, j);
i = i + 1;
j = j - 1;
}
}






c function pointers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 15:55









Swordfish

9,37811436




9,37811436










asked Nov 22 '18 at 15:49









OofOof

42




42













  • tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

    – SPlatten
    Nov 22 '18 at 15:52











  • Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

    – Jabberwocky
    Nov 22 '18 at 15:58





















  • tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

    – SPlatten
    Nov 22 '18 at 15:52











  • Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

    – Jabberwocky
    Nov 22 '18 at 15:58



















tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

– SPlatten
Nov 22 '18 at 15:52





tausche_2 only has two parameters, yet you are calling it with 3, also 'i' and 'j' should be '&i' and '&j'.

– SPlatten
Nov 22 '18 at 15:52













Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

– Jabberwocky
Nov 22 '18 at 15:58







Welcome to stackoverflow, please take the tour, then read this: How to Ask and this: Minimal, Complete, and Verifiable example

– Jabberwocky
Nov 22 '18 at 15:58














1 Answer
1






active

oldest

votes


















0














Since your tausche_2() takes its two parameters as pointers and dereferences them, it operates on the values at the adresses you pass to it. Currently you try to pass 3 parameters with only one of them being a pointer. The right way to call it from change_sequence_2() would be:



tausche_2(&F[i], &F[j]);  // I use the address-of operator to make clear for you,
// that this will pass the adresses of the elements at
// position `i` and `j`.


Alternatively you could add the offsets i and j to F:



tausche_2(F + i, F + j);  // to get the same addresses.


In tausche_2() the passed pointers get dereferenced with *:



temp = *c1;  // assigns temp the value pointed to by c1
*c1 = *c2; // assigns the value pointed to by c1 the value pointed to by c2
*c2 = temp; // assigns the value pointed to by c2 the value of temp


so tausche_2() when called like above effectively operates on the memory pointed to by the parameter char *F of change_sequence_2().






share|improve this answer

























    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%2f53434463%2fhow-to-link-the-2-functions%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














    Since your tausche_2() takes its two parameters as pointers and dereferences them, it operates on the values at the adresses you pass to it. Currently you try to pass 3 parameters with only one of them being a pointer. The right way to call it from change_sequence_2() would be:



    tausche_2(&F[i], &F[j]);  // I use the address-of operator to make clear for you,
    // that this will pass the adresses of the elements at
    // position `i` and `j`.


    Alternatively you could add the offsets i and j to F:



    tausche_2(F + i, F + j);  // to get the same addresses.


    In tausche_2() the passed pointers get dereferenced with *:



    temp = *c1;  // assigns temp the value pointed to by c1
    *c1 = *c2; // assigns the value pointed to by c1 the value pointed to by c2
    *c2 = temp; // assigns the value pointed to by c2 the value of temp


    so tausche_2() when called like above effectively operates on the memory pointed to by the parameter char *F of change_sequence_2().






    share|improve this answer






























      0














      Since your tausche_2() takes its two parameters as pointers and dereferences them, it operates on the values at the adresses you pass to it. Currently you try to pass 3 parameters with only one of them being a pointer. The right way to call it from change_sequence_2() would be:



      tausche_2(&F[i], &F[j]);  // I use the address-of operator to make clear for you,
      // that this will pass the adresses of the elements at
      // position `i` and `j`.


      Alternatively you could add the offsets i and j to F:



      tausche_2(F + i, F + j);  // to get the same addresses.


      In tausche_2() the passed pointers get dereferenced with *:



      temp = *c1;  // assigns temp the value pointed to by c1
      *c1 = *c2; // assigns the value pointed to by c1 the value pointed to by c2
      *c2 = temp; // assigns the value pointed to by c2 the value of temp


      so tausche_2() when called like above effectively operates on the memory pointed to by the parameter char *F of change_sequence_2().






      share|improve this answer




























        0












        0








        0







        Since your tausche_2() takes its two parameters as pointers and dereferences them, it operates on the values at the adresses you pass to it. Currently you try to pass 3 parameters with only one of them being a pointer. The right way to call it from change_sequence_2() would be:



        tausche_2(&F[i], &F[j]);  // I use the address-of operator to make clear for you,
        // that this will pass the adresses of the elements at
        // position `i` and `j`.


        Alternatively you could add the offsets i and j to F:



        tausche_2(F + i, F + j);  // to get the same addresses.


        In tausche_2() the passed pointers get dereferenced with *:



        temp = *c1;  // assigns temp the value pointed to by c1
        *c1 = *c2; // assigns the value pointed to by c1 the value pointed to by c2
        *c2 = temp; // assigns the value pointed to by c2 the value of temp


        so tausche_2() when called like above effectively operates on the memory pointed to by the parameter char *F of change_sequence_2().






        share|improve this answer















        Since your tausche_2() takes its two parameters as pointers and dereferences them, it operates on the values at the adresses you pass to it. Currently you try to pass 3 parameters with only one of them being a pointer. The right way to call it from change_sequence_2() would be:



        tausche_2(&F[i], &F[j]);  // I use the address-of operator to make clear for you,
        // that this will pass the adresses of the elements at
        // position `i` and `j`.


        Alternatively you could add the offsets i and j to F:



        tausche_2(F + i, F + j);  // to get the same addresses.


        In tausche_2() the passed pointers get dereferenced with *:



        temp = *c1;  // assigns temp the value pointed to by c1
        *c1 = *c2; // assigns the value pointed to by c1 the value pointed to by c2
        *c2 = temp; // assigns the value pointed to by c2 the value of temp


        so tausche_2() when called like above effectively operates on the memory pointed to by the parameter char *F of change_sequence_2().







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 16:30

























        answered Nov 22 '18 at 16:02









        SwordfishSwordfish

        9,37811436




        9,37811436






























            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%2f53434463%2fhow-to-link-the-2-functions%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

            Ottavio Pratesi

            Tricia Helfer

            15 giugno