Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-10-2009
Member
 
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?
Reply With Quote
  #2  
Old 10-10-2009
Member
 
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:

Quote:
$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
Quote:
$ 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?
Reply With Quote
  #3  
Old 10-10-2009
Member
 
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]);
Quote:
%c is used to format a character not a string
Yes, so for a string which is used(if possible)?
Quote:
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?
Reply With Quote
  #4  
Old 10-10-2009
Member
 
Join Date: Nov 2008
Posts: 1,054
Re: How to create list in C

Quote:
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
Quote:
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)
Quote:
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 01:32 AM.