|
|
![]() |
|
|
Top | #21 |
|
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175 |
Originally Posted by Mainframeguy
Do you really think a course with this assignment would care about cross platform portability?
![]() Nevertheless, good point. |
|
|
|
|
|
Top | #22 |
|
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220 |
Originally Posted by Zedric
Yes, that would work. Just make sure that if you do it in C to cast the char to int first, and then have the function return a char.
so; char next(char char) { if (char == "Z") return 'A'; else return (int)char + 1; } Simple really. If that code does not work, it is time for me to go read a C book again :P |
|
|
|
|
|
Top | #23 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217 |
Originally Posted by Mainframeguy
hes moved up a notch then in my book, though when writing it on the board he should probably use the proper hex notation and not decimal
though in decimal my point of a 20 difference still stands |
|
|
|
|
|
Top | #24 |
|
OSNN Junior Addict
Joined: October 2004
Location: TU
Posts: 5
Reputation: 0
Power: 93 |
Any voluntier to help me in my 'C' Programming ?
The Question: The fuction below needs to be run in a program. I solved this question but I want you to tell me if it is the wright selution Write a recursive function called AddPos that take in an array of integers intarr and an integer parameter size that holds the number of values in intarr. The function sums up all positive values in intarr and return it. For example AddPos ({-1, 1, -1, 1, -1}, 5) returns 2 (1+1) int AddPos (int intarr, int size) { if (size-1)<0) return 0; else if(intarr [size]>0) sum=sum+intarr[size-1] return sum+AddPos(intarr, size--) } Thank you |
|
|
|
|
|
Top | #25 |
|
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175 |
I assume you didn't compile and test the code? You should, it helps alot!
Code:
int AddPos (int intarr, int size)
{
if (size-1)<0) <-- Wrong number of parenthesis and -1 isn't really needed if you use <= 0 instead
return 0;
else
if(intarr [size]>0) <-- Wrong element (gives error on first attempt) plus I don't know if the space is allowed before []
sum=sum+intarr[size-1] <--- Missing ;
return sum+AddPos(intarr, size--) <--- Missing ;
}
|
|
|
|
|
|
Top | #26 |
|
hypnotika
Joined: January 2004
Location: Minnesota
Posts: 107
Reputation: 40
Power: 104 |
Zedric: you shouldn't give him all the answers, just give him some hints
|
|
|
|
|
|
Top | #27 |
|
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220 |
He is even far from giving him all the answers.
|
|
|
|
|
|
Top | #28 |
|
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175 |
Originally Posted by CHiLLaXen
Did I? At least I didn't give him compilable code.
![]() He would have gotten those on his first compile and test run anyway. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| programming security for OS | dubstar | Web Design & Coding | 6 | June 30th, 2005 6:25pm |
| VB Programming | PseudoKiller | Green Room | 5 | May 23rd, 2005 8:30am |
| C programming project | FishBoy | Web Design & Coding | 4 | November 2nd, 2004 2:03pm |
| c programming | punkandacoke | Windows Desktop Systems | 11 | November 7th, 2003 4:06pm |
| Programming. | DAZZ1 | Windows Desktop Systems | 10 | August 28th, 2003 2:22am |