C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 23rd, 2006, 02:03 AM
jaro jaro is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 35 jaro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 16 m 44 sec
Reputation Power: 4
Send a message via Yahoo to jaro
Character array help.

hi there!
i have a function that retrieve data from a data base. then all of the retrieve data is then converted to a string (character array ) of data.
i don't have any control on how many rows of data are retrieve from the data, so the problem is basically there is not enough space (don't know if this is the right term to use) for the string to put all the retrieve data inside of it.
so far my "temporary" solution to this problem is
Code:
unsigned char dbStr[ 500000 ]="";
w/c is lame.
a friend suggest using a Linked List to solve the problem, but i can't grasp the idea behind it (since i'm a beginner at C )
is there any otherway to solve this problem?.


regards,
jaro

Reply With Quote
  #2  
Old February 23rd, 2006, 07:37 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
You could use calloc() and realloc() to define the array and make it bigger when needed.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Reply With Quote
  #3  
Old February 23rd, 2006, 01:10 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by Itsacon
You could use calloc() and realloc() to define the array and make it bigger when needed.


As far as I know calloc is a one time memory allocation.Does it preserve contents when it is used again for increasing memory space just like realloc??

Reply With Quote
  #4  
Old February 23rd, 2006, 03:12 PM
Icon's Avatar
Icon Icon is online now
Command Line Warrior
Click here for more information. Click here for more information
 
Join Date: Sep 2005
Posts: 756 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 15 h 35 sec
Reputation Power: 4
No it does not, calloc is just a maloc followed by a memset( '\0' ).

Reply With Quote
  #5  
Old February 28th, 2006, 12:04 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Which, since you're using character arrays, is safer than using malloc(), since you'll want empty spaces to be 'nothing', and not accidentally interpretable as another string.

Reply With Quote
  #6  
Old March 4th, 2006, 11:11 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
I'll take a stab at explaining a linked list...think of a treasure hunt. You're given a clue to start. Let's say it has a clue to "whodunit" or whatever, and a hint about where the next clue is. This is our basic LinkedListNode struct, containing members "data" and "next." Next is a pointer to LinkedListNode. In our analogy, it says "look under the tree, behind the barn." In the real thing, it says "look at memory location 0x5744213490." Anyways, when you go to where it says, you get another clue. This has more data, and also information about where the next node can be found.

This is a linked list. It is dynamic because it is not an array; the only information about where the elements are is contained in the previous element, and so you only need a pointer to the first element (called the "head"). Adding an element at the end is a simple matter of allocating a new LinkedListNode and adjusting the "next" pointer of the last element (called the "tail"). Adding or removing elements in the middle is more complicated, but is just a matter of reassigning pointers. This is one of those times where you draw out logic on paper to make sure you know where the pointers are going.

Try and implement this yourself (if you want), if you need more help...that's what we're for.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Character array help.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT