Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-2008, 03:27 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,478
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Storing characters in an array

I need to store delemeters in an array - is it better to do this:

char delem[3] = {'a', 'b', 'c');

or

char delem[3] = {97, 98, 99);

or

char delem[3] = {0x61, 0x62, 0x63);
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-03-2008, 03:48 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,421
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

Do the one that best reflects the intended meaning. They are logically equivalent.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 06:14 PM
broncoslb broncoslb is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 34
Rep Power: 3
broncoslb is on a distinguished road
Default

Another common way to do it is:
Code:
char *myDelims = "abc";
Given the code above you can access a certain index like any other array, e.g. myDelims[0] == 'a'

If you are unsure of the size that the string is going to be, you might want to use the malloc() function to ensure enough space on the heap.
__________________
-Dustin
www.theCprogrammer.com

Last edited by broncoslb; 03-03-2008 at 06:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-04-2008, 01:06 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I just noticed you're switching between { and ), but I suspect it's a typo?

There's no "best way," and it's a matter of style, like WingedPanther pointed out. I would do it a little different though, but the result would be the same:

char delem[] = {'a', 'b', 'c'};

Like you see, you don't have to specify how many elements it's going to contain.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems passing a serialized array in a session variable gszauer PHP Forum 3 02-15-2008 12:18 PM
Help regarding the sorting of arrays with flags! Yuriy M C and C++ 3 10-12-2007 11:30 PM
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 11:49 AM
fread into array position kenna C and C++ 0 08-17-2007 09:03 AM
Python 2D array question annannienann Python 3 04-23-2007 05:36 PM


All times are GMT -5. The time now is 11:20 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads