| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ]=""; 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 |
|
#2
|
||||
|
||||
|
__________________
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
![]() |
|
#3
|
|||
|
|||
|
|
|
#4
|
||||
|
||||
|
No it does not, calloc is just a maloc followed by a memset( '\0' ).
|
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Character array help. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|