Thread: I've been stuck.

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    62

    I've been stuck.

    I want to make a small programme where I input some strings (let's say the names of football teams) and want those strings to get in alphabetical order. I want to input as many strings as I want at the time. Some times I want to put 10, some other time 5 and a third time 23 strings. Don't want to insert them in an arrey, because I don't know how many I will want to put at the time. What should I do? Is list one of the ways to solve it? Is it easy if the part of the programme makes the order A-Z to reverse it to Z-A?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,732
    Personally, I would go with char **teams and make use of realloc to extend the array when you've reached some limit on the number of teams added.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2020
    Posts
    62
    You say if I use an arrey and if that is filled I use the char **teams ?

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    291
    Three options I can see straight off:

    1. Memory is cheap. Why not just set an upper teams of 1000 teams, and 100 character long names. Thats < 0.1 megabyte.

    2. Put them into a linked list, using malloc() to dynamically allocate storage.

    3. Put the into a database.

  5. #5
    Registered User
    Join Date
    Apr 2020
    Posts
    62
    Can you tell me in a few words how to do it with a linked list? What list is the better option on that?

  6. #6
    Registered User
    Join Date
    Sep 2020
    Posts
    80
    Have a look at this tutorial. It uses an int for the data but you could modify to use strings.
    Given a linked list which is sorted, how will you insert in sorted way - GeeksforGeeks

  7. #7
    Registered User
    Join Date
    Apr 2020
    Posts
    62
    That helps. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Got stuck --> need help
    By FrozenMind in forum C Programming
    Replies: 3
    Last Post: 10-26-2010, 02:53 AM
  2. Stuck and need help.
    By tvred in forum C++ Programming
    Replies: 4
    Last Post: 03-23-2010, 11:34 AM
  3. very stuck please help!
    By dac in forum C++ Programming
    Replies: 25
    Last Post: 05-07-2006, 02:45 AM
  4. Stuck
    By goosematt in forum C Programming
    Replies: 1
    Last Post: 11-10-2003, 07:44 AM
  5. Stuck with '\b'
    By pratip in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2003, 07:49 AM

Tags for this Thread