Search in linked list with possibly more results
My semester project is to write a program for telephone book. I'm 3/4 done, but I need to create a modify function, to be able to modify records in my linked list. My question is, that in a telephone book it's possible, that more than one people have the same name, but other telnumber.
In my function the program asks for the name that's wanted to be modified, but if someone search for a name that exists more than once, then how am I able to make a choice between them, which of them is the wanted person?
My struct of the linked list:
typedef struct szemely {
char *veznev;
char *kernev;
char *telnum;
char *varos;
struct szemely *next;
} Person;
c struct linked-list singly-linked-list
|
show 1 more comment
My semester project is to write a program for telephone book. I'm 3/4 done, but I need to create a modify function, to be able to modify records in my linked list. My question is, that in a telephone book it's possible, that more than one people have the same name, but other telnumber.
In my function the program asks for the name that's wanted to be modified, but if someone search for a name that exists more than once, then how am I able to make a choice between them, which of them is the wanted person?
My struct of the linked list:
typedef struct szemely {
char *veznev;
char *kernev;
char *telnum;
char *varos;
struct szemely *next;
} Person;
c struct linked-list singly-linked-list
3
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23
|
show 1 more comment
My semester project is to write a program for telephone book. I'm 3/4 done, but I need to create a modify function, to be able to modify records in my linked list. My question is, that in a telephone book it's possible, that more than one people have the same name, but other telnumber.
In my function the program asks for the name that's wanted to be modified, but if someone search for a name that exists more than once, then how am I able to make a choice between them, which of them is the wanted person?
My struct of the linked list:
typedef struct szemely {
char *veznev;
char *kernev;
char *telnum;
char *varos;
struct szemely *next;
} Person;
c struct linked-list singly-linked-list
My semester project is to write a program for telephone book. I'm 3/4 done, but I need to create a modify function, to be able to modify records in my linked list. My question is, that in a telephone book it's possible, that more than one people have the same name, but other telnumber.
In my function the program asks for the name that's wanted to be modified, but if someone search for a name that exists more than once, then how am I able to make a choice between them, which of them is the wanted person?
My struct of the linked list:
typedef struct szemely {
char *veznev;
char *kernev;
char *telnum;
char *varos;
struct szemely *next;
} Person;
c struct linked-list singly-linked-list
c struct linked-list singly-linked-list
edited Nov 22 at 18:38
Swordfish
1
1
asked Nov 22 at 18:35
László Sipula
61
61
3
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23
|
show 1 more comment
3
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23
3
3
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23
|
show 1 more comment
2 Answers
2
active
oldest
votes
Display a list of possible choices and have the operator pick which one, either by number, in a terminal, or through other interface selection methods (button, link, checkbox, or the like).
What interface will the program be targeting?
add a comment |
The modify
function won't handle the search at all. You'll need (want) a separate function for the name search, call it person_lookup
or something.
There's a few things you want to do.
- person lookup by name
- show lookup results to user
- accept user selection (i.e. the user will select a person from a numbered list)
- modify that person's information that the user selected.
psuedo-code:
struct Person *person;
struct Person *persons;
/* return a list of names or NULL if none are found */
persons = lookup_person(name)
if (persons is NULL)
handle_no_results_found && return;
/* user_selection_from() will display the matched lookup names
* as a numbered list. The user will select a number from the
* list that corresponds to a name.
*/
person = user_selection_from(persons);
/* the user didn't select a name from the list */
if (person is NULL)
handle_no_user_selection && return;
/* modify the person the user selected */
error = modify(person);
if (error)
alert_user_unable_to_modify_person;
As I said, this is psuedo-code, not entirely correct - but it should give you an idea or (hopefully) put you on the right path.
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%2f53436553%2fsearch-in-linked-list-with-possibly-more-results%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
Display a list of possible choices and have the operator pick which one, either by number, in a terminal, or through other interface selection methods (button, link, checkbox, or the like).
What interface will the program be targeting?
add a comment |
Display a list of possible choices and have the operator pick which one, either by number, in a terminal, or through other interface selection methods (button, link, checkbox, or the like).
What interface will the program be targeting?
add a comment |
Display a list of possible choices and have the operator pick which one, either by number, in a terminal, or through other interface selection methods (button, link, checkbox, or the like).
What interface will the program be targeting?
Display a list of possible choices and have the operator pick which one, either by number, in a terminal, or through other interface selection methods (button, link, checkbox, or the like).
What interface will the program be targeting?
answered Nov 22 at 18:47
hellork
935
935
add a comment |
add a comment |
The modify
function won't handle the search at all. You'll need (want) a separate function for the name search, call it person_lookup
or something.
There's a few things you want to do.
- person lookup by name
- show lookup results to user
- accept user selection (i.e. the user will select a person from a numbered list)
- modify that person's information that the user selected.
psuedo-code:
struct Person *person;
struct Person *persons;
/* return a list of names or NULL if none are found */
persons = lookup_person(name)
if (persons is NULL)
handle_no_results_found && return;
/* user_selection_from() will display the matched lookup names
* as a numbered list. The user will select a number from the
* list that corresponds to a name.
*/
person = user_selection_from(persons);
/* the user didn't select a name from the list */
if (person is NULL)
handle_no_user_selection && return;
/* modify the person the user selected */
error = modify(person);
if (error)
alert_user_unable_to_modify_person;
As I said, this is psuedo-code, not entirely correct - but it should give you an idea or (hopefully) put you on the right path.
add a comment |
The modify
function won't handle the search at all. You'll need (want) a separate function for the name search, call it person_lookup
or something.
There's a few things you want to do.
- person lookup by name
- show lookup results to user
- accept user selection (i.e. the user will select a person from a numbered list)
- modify that person's information that the user selected.
psuedo-code:
struct Person *person;
struct Person *persons;
/* return a list of names or NULL if none are found */
persons = lookup_person(name)
if (persons is NULL)
handle_no_results_found && return;
/* user_selection_from() will display the matched lookup names
* as a numbered list. The user will select a number from the
* list that corresponds to a name.
*/
person = user_selection_from(persons);
/* the user didn't select a name from the list */
if (person is NULL)
handle_no_user_selection && return;
/* modify the person the user selected */
error = modify(person);
if (error)
alert_user_unable_to_modify_person;
As I said, this is psuedo-code, not entirely correct - but it should give you an idea or (hopefully) put you on the right path.
add a comment |
The modify
function won't handle the search at all. You'll need (want) a separate function for the name search, call it person_lookup
or something.
There's a few things you want to do.
- person lookup by name
- show lookup results to user
- accept user selection (i.e. the user will select a person from a numbered list)
- modify that person's information that the user selected.
psuedo-code:
struct Person *person;
struct Person *persons;
/* return a list of names or NULL if none are found */
persons = lookup_person(name)
if (persons is NULL)
handle_no_results_found && return;
/* user_selection_from() will display the matched lookup names
* as a numbered list. The user will select a number from the
* list that corresponds to a name.
*/
person = user_selection_from(persons);
/* the user didn't select a name from the list */
if (person is NULL)
handle_no_user_selection && return;
/* modify the person the user selected */
error = modify(person);
if (error)
alert_user_unable_to_modify_person;
As I said, this is psuedo-code, not entirely correct - but it should give you an idea or (hopefully) put you on the right path.
The modify
function won't handle the search at all. You'll need (want) a separate function for the name search, call it person_lookup
or something.
There's a few things you want to do.
- person lookup by name
- show lookup results to user
- accept user selection (i.e. the user will select a person from a numbered list)
- modify that person's information that the user selected.
psuedo-code:
struct Person *person;
struct Person *persons;
/* return a list of names or NULL if none are found */
persons = lookup_person(name)
if (persons is NULL)
handle_no_results_found && return;
/* user_selection_from() will display the matched lookup names
* as a numbered list. The user will select a number from the
* list that corresponds to a name.
*/
person = user_selection_from(persons);
/* the user didn't select a name from the list */
if (person is NULL)
handle_no_user_selection && return;
/* modify the person the user selected */
error = modify(person);
if (error)
alert_user_unable_to_modify_person;
As I said, this is psuedo-code, not entirely correct - but it should give you an idea or (hopefully) put you on the right path.
answered Nov 22 at 19:24
fbynite
2,44711320
2,44711320
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%2f53436553%2fsearch-in-linked-list-with-possibly-more-results%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
3
You could present the user with a list of search results and ask again to identify the record he wants to modify.
– Swordfish
Nov 22 at 18:39
The program can't guess, so the obvious answer is make the user choose. Or, make it so there can't be two contacts with the same name to begin with.
– Havenard
Nov 22 at 19:18
@Havenard, so you're saying there should only be one John Smith per phonebook?
– fbynite
Nov 22 at 19:37
@fbynite You can alias them, "John Smith (Work)", "John Smith (Mechanic)", "John Smith (Bank Manger)". And normally you would, sometimes even if there was only one person with that name, after all you're not supposed to remember who everyone in your list is and why they are even in there, those notes are not only extremely helpful but also solve this problem.
– Havenard
Nov 22 at 19:40
@Havenard, so you're saying you can only have mechanic named John Smith?
– fbynite
Nov 22 at 20:23