hello
i need to have a program to do this .... read 5 ints from user, print
the min and max ..... also print the ints hi to lo and lo to hi using
qsort. this is what i did but i gots stuck
Ohhhhhhhh.... a homework problem. Can we give grades? ;-)
void main(int narg, char **args){
First mistake.
main() returns int on a hosted environment. Rewrite this as
int main(int narg, char **args) {
a is an array of five integers
a[1]=args[1];
a[2]=args[2];
a[3]=args[3];
a[4]=args[4];
a[5]=args[5];
Second, third, fourth and fifth mistakes
* Error of ommission: In C, arrays are "zero addressed". This means that the
first array element is [0], the second element is [1], etc. What are you
going to do about a[0] and args[0]? What do you want to do with them?
* Error of commission: a[5] does not exist; a is an array of five integers,
held in a[0] through a[4].
* Error of commission: args[] is an array of pointers to characters, a[] is
an array of integers. The two are not compatable. How are you going to
reconcile this?
* How many args were actually passed to main? Are you certain that 6
arguments (args[0] through args[5]) were passed? What if only args[0]
through args[2] were passed? What happens then?
qsort(args);//how how how????
Sixth, seventh, and (possibly) eighth mistakes:
qsort() requires four arguments. It takes
a) a pointer (of type void) to the beginning of the array to be sorted,
b) a count (of type size_t) of the number of entries in the array,
c) a count (of type size_t) of the size (in bytes) of one entry (all entries
are assumed to be of uniform size), and
d) a pointer (of type function_returning_int) to a function that will
compare two given entries and return an integer indicating whether the
1st entry was less than, equal to, or greater than the 2nd entry.
* You neglect to include the prototype for qsort(),
* You only pass one argument to qsort()
* You do not pass the integer array to qsort, but instead pass the original
args[] pointer. So why did you code the a[] array stuff in the first place?
Ninth? mistake
main() returns an int. Don't depend on the compiler to do that for you
(although, some compilers for some levels of C will do so). You really
should return a value here. Try 0
}
u guys are the experts so plz can u do this. i need it friday so that
should be plenty of time yes?
To do your homework for you? Sure, a week should be enough time for this
level of work. How about you give us your prof's email address, so we can
email our work to him. I sure that he'd appreciate knowing how much of your
solution was yours (and thus, how much you *LEARNED*) and how much was
someone elses.
plz respond to email because i have iphone.
Sorry, but your disability is none of my concern.
Anyway, the cardinal rule of usenet is "you post here, you read here". email
replies are frowned apon; it deprives others from our pearls of wisdom.
thx guys for helping .... i appreciate!!!!
Not as much as we appreciate the laugh you've given us.
Luck be with you.... you're going to need it.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------