How to link the 2 functions
up vote
-1
down vote
favorite
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
add a comment |
up vote
-1
down vote
favorite
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
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 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 at 15:58
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
c function pointers
edited Nov 22 at 15:55
Swordfish
1
1
asked Nov 22 at 15:49
Oof
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 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 at 15:58
add a comment |
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 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 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 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 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 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 at 15:58
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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()
.
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%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
up vote
0
down vote
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()
.
add a comment |
up vote
0
down vote
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()
.
add a comment |
up vote
0
down vote
up vote
0
down vote
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()
.
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()
.
edited Nov 22 at 16:30
answered Nov 22 at 16:02
Swordfish
1
1
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53434463%2fhow-to-link-the-2-functions%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
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 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 at 15:58