Teen Programmers Unite  
 

 

Return to forum top

got stuck need little assistance...

Posted by matheo917 [send private reply] at September 01, 2001, 10:02:18 PM

i am writing a program, one part of this program consists of a function that needs to alphabetize 100 words (strings) that were read in from a file before, i am simply looking for a function besides (basic_string::compare()), some simple function that has a capability to put the words in alphabetized manner. Right now i am playing around with different string manipulators like strcmp(str1, str2) but it's taking me too many different checks and if statments, or maybe just a simple function that analizes every character of the string...???

i am also looking for a function that specifies where the output to the file could be placed, for example: if you want to put a string "hello" at the beginning of the 15th column of the 7th row...???

thanx
you can e-mail me at matheo917@home.com

Posted by lordaerom [send private reply] at September 02, 2001, 03:04:56 AM

You might want to have a look at qsort.

Posted by Psion [send private reply] at September 02, 2001, 02:00:25 PM

Lordaerom's suggestion is a good one. In C++, you can also sort using STL algorithms on data items with comparison operators defined.

As to your second question, "columns" and "rows" do not exist in files. If you want files to have these, you'll have to come up with your own format and enforce it. You can use fseek() with C I/O to skip ahead/back to certain bytes in a file, if they have already been written previously.

Posted by matheo917 [send private reply] at September 02, 2001, 02:16:17 PM

that's a really usefull advice, thanx

i am playing around with qsort() now:
i am using something like this...

void qsort(void *str[0], size_t 100, size_t 8,
int (strcmp(str[i],str[++i])
*fcmp)(const void *, const void*));

it doesn't want to work too well....hmmmm

what do you guys think...????

Posted by taubz [send private reply] at September 02, 2001, 02:52:50 PM

fcmp is supposed to be a pointer to a comparison function which you implement. A pointer to a function is just the name of the function itself, eg:

qsort(str[0], 100, 8, strcmp);

I don't know if strcmp is a valid comparison function, tho, because it needs to take certain arguments. It might be. Should be. Try that.

- taubz

Posted by lordaerom [send private reply] at September 02, 2001, 10:28:22 PM

strcmp isn't a valid comparison function.
The comaprison function is of the form 'int cmpfunc(const void*, const void*)', whereas strcmp is char* instead of void*. GCC at least doesn't like that.

qtest.cpp:33: converting `int (*)(const char *, const char *)' to `int (*)(const void *, const void *)' is a contravariance violation

Posted by taubz [send private reply] at September 03, 2001, 06:04:42 PM

What's contravariance? :)

Posted by lordaerom [send private reply] at September 03, 2001, 09:10:57 PM

ask the gcc programmers =]

Contra \Con"tra\
A Latin adverb and preposition, signifying against, contrary,
in opposition, etc., entering as a prefix into the
composition of many English words. Cf. {Counter}, adv. &
pref.

Variance \Va"ri*ance\, n. [L. variantia.]
1. The quality or state of being variant; change of
condition; variation.
(etc)

A contrary variance violation? =]. Against the proper allowable variance? =]

Posted by taubz [send private reply] at September 04, 2001, 09:24:53 AM

Thanks, that really helped.

- taubz

Posted by lordaerom [send private reply] at September 04, 2001, 02:38:02 PM

You're the one that asked.
Your sarcasm is not appreciated.

Posted by taubz [send private reply] at September 04, 2001, 04:29:13 PM

Sorry...

Posted by lordaerom [send private reply] at September 04, 2001, 04:51:34 PM

That is better!!

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.