c program helps

K

kyle merrand

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

void main(int narg, char **args){
int a[5];
a[1]=args[1];
a[2]=args[2];
a[3]=args[3];
a[4]=args[4];
a[5]=args[5];
qsort(args);//how how how????
return;}

u guys are the experts so plz can u do this. i need it friday so that
should be plenty of time yes? plz respond to email because i have
iphone. thx guys for helping .... i appreciate!!!!
 
L

Lew Pitcher

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) {

int a[5];
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. ------
 
K

Keith Thompson

kyle merrand said:
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
[...]
qsort(args);//how how how????
[...]

This is obviously homework, so you're obviously taking a class,
so you obviously have a textbook or something similar. Look up
"qsort" in the index. Read it.

[...]
 
G

Guest

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

<snip>

a pseudo code solution might look something like this

(define homework
(lambda (int-list)
(display "min: ") (display (apply min int-list)) (newline)
(display "max: ") (display (apply max int-list)) (newline)
(display "ascending: ") (display (sort int-list <)) (newline)
(display "descending: ") (display (reverse (sort int-list <)))
(newline)))

with atypical test run looking like this
(homework '(10 1 9 2 8))
min: 1
max: 10
ascending: (1 2 8 9 10)
descending: (10 9 8 2 1)

translating it into C is left as an exercise for you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top