Update cell in struct list and return the list
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm looking for a way to update a cell in a struct list.
I have a struct list:
struct _list {
int startNode,
targetNode,
substitute;
unsigned char letter;
struct _list *next;
}
And a function that enables me to update a cell.
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
return list;
}
list = list -> next;
}
return NULL;
}
My problem is that this function do not return the whole list. How could I proceed to do so?
c
add a comment |
I'm looking for a way to update a cell in a struct list.
I have a struct list:
struct _list {
int startNode,
targetNode,
substitute;
unsigned char letter;
struct _list *next;
}
And a function that enables me to update a cell.
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
return list;
}
list = list -> next;
}
return NULL;
}
My problem is that this function do not return the whole list. How could I proceed to do so?
c
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?
– Jose
Jan 3 at 10:21
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29
add a comment |
I'm looking for a way to update a cell in a struct list.
I have a struct list:
struct _list {
int startNode,
targetNode,
substitute;
unsigned char letter;
struct _list *next;
}
And a function that enables me to update a cell.
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
return list;
}
list = list -> next;
}
return NULL;
}
My problem is that this function do not return the whole list. How could I proceed to do so?
c
I'm looking for a way to update a cell in a struct list.
I have a struct list:
struct _list {
int startNode,
targetNode,
substitute;
unsigned char letter;
struct _list *next;
}
And a function that enables me to update a cell.
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
return list;
}
list = list -> next;
}
return NULL;
}
My problem is that this function do not return the whole list. How could I proceed to do so?
c
c
asked Jan 3 at 10:15


Thomas DI GREGORIOThomas DI GREGORIO
31
31
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?
– Jose
Jan 3 at 10:21
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29
add a comment |
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?
– Jose
Jan 3 at 10:21
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?– Jose
Jan 3 at 10:21
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?– Jose
Jan 3 at 10:21
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29
add a comment |
3 Answers
3
active
oldest
votes
Add a new var whole_list
.
The following code
could work:
struct _list *insertSubstitute(struct _list *list,
int startNode,
unsigned char letter,
int substitute) {
struct _list* whole_list = list;
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
break;
}
list = list -> next;
}
return whole_list;
}
add a comment |
you need just to use a temporary pointer to your list to check the elements since you are using the list it self its causing you the problem
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
struct _list *temp=list;
while (temp!= NULL) {
if (temp-> letter == letter && temp-> startNode == startNode) {
temp -> substitute = substitute;
break;
}
temp= temp-> next;
}
return list;
}
add a comment |
Try this:
void insertSubstitute(struct _list** list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
while (*list != NULL) {
if ((*list) -> letter == letter && (*list) -> startNode == startNode) {
(*list) -> substitute = substitute;
return;
}
(*list) = (*list) -> next;
}
}
When you call this version of the function, you need to pass the address of your list.
Or another version of the original:
struct _list*insertSubstitute(struct _list* list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
struct _list* rc = list;
while (rc != NULL) {
if (rc -> letter == letter && rc -> startNode == startNode) {
rc -> substitute = substitute;
return rc;
}
rc = rc -> next;
}
return NULL;
}
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%2f54020214%2fupdate-cell-in-struct-list-and-return-the-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add a new var whole_list
.
The following code
could work:
struct _list *insertSubstitute(struct _list *list,
int startNode,
unsigned char letter,
int substitute) {
struct _list* whole_list = list;
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
break;
}
list = list -> next;
}
return whole_list;
}
add a comment |
Add a new var whole_list
.
The following code
could work:
struct _list *insertSubstitute(struct _list *list,
int startNode,
unsigned char letter,
int substitute) {
struct _list* whole_list = list;
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
break;
}
list = list -> next;
}
return whole_list;
}
add a comment |
Add a new var whole_list
.
The following code
could work:
struct _list *insertSubstitute(struct _list *list,
int startNode,
unsigned char letter,
int substitute) {
struct _list* whole_list = list;
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
break;
}
list = list -> next;
}
return whole_list;
}
Add a new var whole_list
.
The following code
could work:
struct _list *insertSubstitute(struct _list *list,
int startNode,
unsigned char letter,
int substitute) {
struct _list* whole_list = list;
while (list != NULL) {
if (list -> letter == letter && list -> startNode == startNode) {
list -> substitute = substitute;
break;
}
list = list -> next;
}
return whole_list;
}
answered Jan 3 at 10:24


Yunbin LiuYunbin Liu
1,2762515
1,2762515
add a comment |
add a comment |
you need just to use a temporary pointer to your list to check the elements since you are using the list it self its causing you the problem
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
struct _list *temp=list;
while (temp!= NULL) {
if (temp-> letter == letter && temp-> startNode == startNode) {
temp -> substitute = substitute;
break;
}
temp= temp-> next;
}
return list;
}
add a comment |
you need just to use a temporary pointer to your list to check the elements since you are using the list it self its causing you the problem
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
struct _list *temp=list;
while (temp!= NULL) {
if (temp-> letter == letter && temp-> startNode == startNode) {
temp -> substitute = substitute;
break;
}
temp= temp-> next;
}
return list;
}
add a comment |
you need just to use a temporary pointer to your list to check the elements since you are using the list it self its causing you the problem
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
struct _list *temp=list;
while (temp!= NULL) {
if (temp-> letter == letter && temp-> startNode == startNode) {
temp -> substitute = substitute;
break;
}
temp= temp-> next;
}
return list;
}
you need just to use a temporary pointer to your list to check the elements since you are using the list it self its causing you the problem
struct _list *insertSubstitute(struct _list *list, int startNode,
unsigned char letter, int substitute) {
struct _list *temp=list;
while (temp!= NULL) {
if (temp-> letter == letter && temp-> startNode == startNode) {
temp -> substitute = substitute;
break;
}
temp= temp-> next;
}
return list;
}
answered Jan 3 at 10:25


SpinkooSpinkoo
1,7701216
1,7701216
add a comment |
add a comment |
Try this:
void insertSubstitute(struct _list** list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
while (*list != NULL) {
if ((*list) -> letter == letter && (*list) -> startNode == startNode) {
(*list) -> substitute = substitute;
return;
}
(*list) = (*list) -> next;
}
}
When you call this version of the function, you need to pass the address of your list.
Or another version of the original:
struct _list*insertSubstitute(struct _list* list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
struct _list* rc = list;
while (rc != NULL) {
if (rc -> letter == letter && rc -> startNode == startNode) {
rc -> substitute = substitute;
return rc;
}
rc = rc -> next;
}
return NULL;
}
add a comment |
Try this:
void insertSubstitute(struct _list** list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
while (*list != NULL) {
if ((*list) -> letter == letter && (*list) -> startNode == startNode) {
(*list) -> substitute = substitute;
return;
}
(*list) = (*list) -> next;
}
}
When you call this version of the function, you need to pass the address of your list.
Or another version of the original:
struct _list*insertSubstitute(struct _list* list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
struct _list* rc = list;
while (rc != NULL) {
if (rc -> letter == letter && rc -> startNode == startNode) {
rc -> substitute = substitute;
return rc;
}
rc = rc -> next;
}
return NULL;
}
add a comment |
Try this:
void insertSubstitute(struct _list** list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
while (*list != NULL) {
if ((*list) -> letter == letter && (*list) -> startNode == startNode) {
(*list) -> substitute = substitute;
return;
}
(*list) = (*list) -> next;
}
}
When you call this version of the function, you need to pass the address of your list.
Or another version of the original:
struct _list*insertSubstitute(struct _list* list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
struct _list* rc = list;
while (rc != NULL) {
if (rc -> letter == letter && rc -> startNode == startNode) {
rc -> substitute = substitute;
return rc;
}
rc = rc -> next;
}
return NULL;
}
Try this:
void insertSubstitute(struct _list** list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
while (*list != NULL) {
if ((*list) -> letter == letter && (*list) -> startNode == startNode) {
(*list) -> substitute = substitute;
return;
}
(*list) = (*list) -> next;
}
}
When you call this version of the function, you need to pass the address of your list.
Or another version of the original:
struct _list*insertSubstitute(struct _list* list
,int startNode
,unsigned char letter
,int substitute) {
if ( list == NULL ) {
//Do nothing list is invalid
return;
}
struct _list* rc = list;
while (rc != NULL) {
if (rc -> letter == letter && rc -> startNode == startNode) {
rc -> substitute = substitute;
return rc;
}
rc = rc -> next;
}
return NULL;
}
answered Jan 3 at 10:33
SPlattenSPlatten
2,23531953
2,23531953
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.
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%2f54020214%2fupdate-cell-in-struct-list-and-return-the-list%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
insertSubstitute
gets a pointer to a struct, so you are modifying the source. Why do you want to return it?– Jose
Jan 3 at 10:21
Changed your function prototype from 'struct _list*' list to 'struct _list**', you cannot modify a pointer and return it back but you can modify a pointer when you pass a pointer to the pointer, you will need to change internal references to list to '(*list)->, if you do this then you can get rid of the return and change the function return to void.
– SPlatten
Jan 3 at 10:29