Search in linked list with possibly more results












0














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;









share|improve this question




















  • 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
















0














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;









share|improve this question




















  • 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














0












0








0


1





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;









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












2 Answers
2






active

oldest

votes


















0














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?






share|improve this answer





























    0














    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.




    1. person lookup by name

    2. show lookup results to user

    3. accept user selection (i.e. the user will select a person from a numbered list)

    4. 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.






    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%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









      0














      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?






      share|improve this answer


























        0














        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?






        share|improve this answer
























          0












          0








          0






          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?






          share|improve this answer












          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?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 18:47









          hellork

          935




          935

























              0














              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.




              1. person lookup by name

              2. show lookup results to user

              3. accept user selection (i.e. the user will select a person from a numbered list)

              4. 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.






              share|improve this answer


























                0














                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.




                1. person lookup by name

                2. show lookup results to user

                3. accept user selection (i.e. the user will select a person from a numbered list)

                4. 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.






                share|improve this answer
























                  0












                  0








                  0






                  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.




                  1. person lookup by name

                  2. show lookup results to user

                  3. accept user selection (i.e. the user will select a person from a numbered list)

                  4. 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.






                  share|improve this answer












                  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.




                  1. person lookup by name

                  2. show lookup results to user

                  3. accept user selection (i.e. the user will select a person from a numbered list)

                  4. 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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 at 19:24









                  fbynite

                  2,44711320




                  2,44711320






























                      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.





                      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.




                      draft saved


                      draft discarded














                      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





















































                      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

                      Trompette piccolo

                      Slow SSRS Report in dynamic grouping and multiple parameters

                      Simon Yates (cyclisme)