Power with Strings & Arrays

Discuss topics that apply across the products, such as the PocketC language, or development in general

Postby Gazza on Wed Jan 16, 2002 4:35 am

I have created this topic to build a wealth of programming routines to sort and remove and change data,

Ok these are the sort I things I would like to achive,

*Remove an array from an array list, then re-shuffle the array so that it closes up the gap.

*Insert data into an array in a particular place

* Create an Array and mix up the data

// More to Come // I am working out these problems but would appreciate any help, Thanks everyone.....

Edited by - Gazza on 01/15/2002 22:37:50
Posts: 146
Joined: Sat Jan 12, 2002 1:56 am
Location: United Kingdom

Postby guy on Wed Jan 16, 2002 11:09 am

If you're interested in code that manages "arrays" that can have elements removed and reordered then take at look at my linked list/tree library. You can download the source from the pcform page (link in sig). Although this was written for the CE version of PocketC it should work with both versions (may require some small tweaking for Palm).

It allows you to create collections of items. Items can have several fields and can be reordered or deleted. Items can own other collections of items. Items have constructors and destructors. There are functions to walk the lists and call a function of your choice for each item (like enumerators).

The data structures that it manages are very heavily used in pcform and I've not had any reports of bugs or memory leakage in the code.

It would be easy to add a quicksort function to the library so that a list could be sorted automatically, calling a user defined comparison function for each item.

PocketC CE API interface: http://www.networkdynamics.net/pcktceapi.zip

Edited by - guy on 01/16/2002 05:12:31
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby Gazza on Thu Jan 17, 2002 9:08 am

It would not install onto the pc, I really want to stay away from the api, I would like to write native code, but I am not quite that far yet & can you write Native Libarys using pocket c, I could possible do most of these tasks, its just the @[] does not work, I have tried this and just get an error

str @[1] = 'W';
Posts: 146
Joined: Sat Jan 12, 2002 1:56 am
Location: United Kingdom

Postby Gazza on Fri Jan 18, 2002 5:05 am

Ok Here The First to Randomize a String

// Random String

string person[3];
string new[6];

nxt(int x, string hold) {
string tmp; int t,y; t=x;
while(x) {
x--; }

while(t) {
hold=hold+new[t]; }
puts(hold); }

main() {
int x;
string hold;
hold = person[0];
x = strlen(hold);
nxt(x,hold); }

This uses Joe Stadolnik Algo to Randomize the Array, I am working on this program with pointers to reduce the code.
Posts: 146
Joined: Sat Jan 12, 2002 1:56 am
Location: United Kingdom

Postby Gazza on Fri Jan 18, 2002 7:45 am

ok here is the same program using pointers, not sure why ret = ctostr(ptr); does not return all data from the pointer, hence the loop.

// Rand String

string per[3];
pointer ptr;

main() {
string str,tmp,ret;
int len,y,i;
str = per[0];
len = strlen(str)+1;
ptr = malloc(len);
settype(ptr, len, 'c');
strtoc(str, ptr);

while(len) {
ptr[i]=tmp; }

// ret = ctostr(ptr);
for(y=0; y<strlen(str)+1; y++)
{puts(ptr[y]); }
free(ptr); }
Posts: 146
Joined: Sat Jan 12, 2002 1:56 am
Location: United Kingdom

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests