Thread: [newbie] Input list/array of strings then sort?

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    [newbie] Input list/array of strings then sort?

    Hey,

    C newbie here. I have an assignment to input a list of names then sort them alphabetically. I'm alright with the sorting I think. But only once I figure out how to save the list of strings.

    So do I need an array?

    I tried delaring

    char name[n][10]; //n being the amount of names required, as input by the user, 10 being the max characters in a name. this look right?

    but it said: error C2143: syntax error : missing ';' before 'type'

    I was hoping to have a for loop of printf and scanf to get all the names.

    Any tips on this? Thanks!

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    72
    Post your code.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    char name[n][10] is fine IF (1) you already know what n is and (2) you don't have your compiler stuck in "old" mode so that it will allow you to use variably-subscripted arrays. If one or the other of those is false, then you're in trouble.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To sort an input file and write it as multiple files
    By kavithanarayan in forum C++ Programming
    Replies: 6
    Last Post: 03-16-2010, 12:35 AM
  2. Using dynamically allocated strings to sort words
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-13-2009, 04:01 PM
  3. Using dynamically allocated strings to sort words
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-12-2009, 09:10 PM
  4. bubble sort array of strings
    By the_head in forum C Programming
    Replies: 1
    Last Post: 04-02-2002, 05:15 PM
  5. Format User Input When using strings
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-08-2002, 03:59 AM