Results 1 to 4 of 4

Thread: How to create list in C

  1. #1
    Join Date
    Jan 2009
    Posts
    638

    How to create list in C

    I am beginner in C and in many programs I want to create a list of words. For example:

    Code:
    void main() 
    {
    char tab[3] = ("hello", "a", "all"); 
    printf ( "%c%c%c", tab[1], tab[2], tab[3]); 
    getch (); 
    }
    Except, of course, it does not works because the words are already in tables. Could you help me please? How to create list in C?

  2. #2
    Join Date
    Nov 2008
    Posts
    1,054

    Re: How to create list in C

    There is a problem in main function, getch is not a standard function,%c is used to format a character not a string, the C arrays are indexed from 0's (so your tab[3] is out of bounds) and finally your table is an array of strings and not an array of characters.

    You must have got a very crappy message like this:

    $clang test.c
    test.c:4:18: warning: initializer-string for char array is too long
    char tab[3]={"hello","a","all"};
    ^~~~~~~~~
    test.c:4:28: warning: excess elements in char array initializer
    char tab[3]={"hello","a","all"};
    ^~~
    2 diagnostics generated.
    Undefined symbols:
    "_getch", referenced from:
    _main in cc-UrkVLX.o
    ld: symbol(s) not found
    $ gcc test.c
    test.c: In function ‘main’:
    test.c:4: error: excess elements in char array initializer
    test.c:4: error: (near initialization for ‘tab’)
    test.c:4: error: excess elements in char array initializer
    test.c:4: error: (near initialization for ‘tab’)
    test.c:4: warning: initializer-string for array of chars is too long
    test.c:3: warning: return type of ‘main’ is not ‘int’

  3. #3
    Join Date
    Jan 2009
    Posts
    638

    Re: How to create list in C

    For the main(), its true that I usually use: main(int argc, char *argv[])
    getch() is associated with a function getchar() by my compiler
    And indeed for the size of the table I did not read (I often makes mistake), I wanted to put this: ...,tab[0],tab[1],tab[2]);
    %c is used to format a character not a string
    Yes, so for a string which is used(if possible)?
    finally your table is an array of strings and not an array of characters.
    I know, but I do not want to treat each letter one by one. Is it not possible to make an array of 2 dimensions? 1st: chains, 2nd: characters

    Finally, there is indeed a solution in C to make a list of words or not?

  4. #4
    Join Date
    Nov 2008
    Posts
    1,054

    Re: How to create list in C

    For the main(), its true that I usually use: main(int argc, char *argv[])
    The correct signature is indicated in the warnings of compilers that I copied
    getch() is associated with a function getchar() by my compiler
    So use getchar (or nothing at all, it's not like your getch is mandatory in C program)
    I know, but I do not want to treat each letter one by one. Is it not possible to make an array of 2 dimensions? 1st: chains, 2nd: characters
    Of course, if reflected in the type of a string in C and put it in a table

Similar Threads

  1. I want to create a list of Tracks in SSX Game
    By Nityaa in forum Video Games
    Replies: 1
    Last Post: 01-03-2012, 04:53 AM
  2. Unable to create a wish list in FrontierVille
    By Raja Ram in forum Video Games
    Replies: 7
    Last Post: 16-03-2011, 10:24 PM
  3. How to create a bulleted or numbered list in Word?
    By desilva in forum Windows Software
    Replies: 5
    Last Post: 21-03-2010, 06:36 AM
  4. How to create dropdown list under tab in HTML
    By Mentos in forum Windows Software
    Replies: 3
    Last Post: 30-07-2009, 11:49 AM
  5. How to create a distribution list in Outlook
    By SpearMan in forum Tips & Tweaks
    Replies: 1
    Last Post: 18-02-2009, 02:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,664,532.02983 seconds with 17 queries