Reply
Old October 29th, 2004 Top | #21

OSNN Folding Team  
Zedric's Avatar
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175

Cool

Originally Posted by Mainframeguy
Agreed - plus if he starts to embed things like ASCII tables he may actually LOSE points since it will lose cross platform portability, say if it had to compile and run with EBCDIIC instead (where the alpha characters are not even consecutive
Do you really think a course with this assignment would care about cross platform portability?

Nevertheless, good point.


Did I help you? Please use the reputation system. Click the icon on the left!
Proud host of the OSNN.net folding sigs. Want one? Check the folding thread!
http://zedric.no-ip.com/
Zedric is offline   Reply With Quote
Old October 29th, 2004 Top | #22
 
X-Istence's Avatar
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220

Default

Originally Posted by Zedric
Wouldn't

if chr == 'Z' then
return 'A'
else
return chr+1

work? Without having to complicate things with ASCII tables...

(not in C notation I know, but it was on purpose )
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
X-Istence is offline   Reply With Quote
Old October 29th, 2004 Top | #23

OSNN Folding Team  
Geffy's Avatar
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217

Default

Originally Posted by Mainframeguy
First - just off my head I kinow he was right and you are also wrong, you see in HEX the numbers add up fine.....

Second you got it back to front - UPPER case starts at x'41' and LOWER ar x'61'

Sorry to be a smart ass, but I thought I should clear that up, since this is meant to be a "learning" thread
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


blogtumbloglastfmflickr#rubyonrails@twitter
"I could be replaced with a very small shell script"
Geffy is offline   Reply With Quote
Old November 1st, 2004 Top | #24
 
dal2lad's Avatar
OSNN Junior Addict
Joined: October 2004
Location: TU
Posts: 5
Reputation: 0
Power: 93

Default

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
dal2lad is offline   Reply With Quote
Old November 1st, 2004 Top | #25

OSNN Folding Team  
Zedric's Avatar
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175

Cool

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 ;
}


Did I help you? Please use the reputation system. Click the icon on the left!
Proud host of the OSNN.net folding sigs. Want one? Check the folding thread!
http://zedric.no-ip.com/
Zedric is offline   Reply With Quote
Old November 1st, 2004 Top | #26
 
CHiLLaXen's Avatar
hypnotika
Joined: January 2004
Location: Minnesota
Posts: 107
Reputation: 40
Power: 104

Default

Zedric: you shouldn't give him all the answers, just give him some hints
CHiLLaXen is offline   Reply With Quote
Old November 1st, 2004 Top | #27
 
X-Istence's Avatar
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220

Default

He is even far from giving him all the answers.
X-Istence is offline   Reply With Quote
Old November 1st, 2004 Top | #28

OSNN Folding Team  
Zedric's Avatar
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 175

Cool

Originally Posted by CHiLLaXen
Zedric: you shouldn't give him all the answers, just give him some hints
Did I? At least I didn't give him compilable code.

He would have gotten those on his first compile and test run anyway.


Did I help you? Please use the reputation system. Click the icon on the left!
Proud host of the OSNN.net folding sigs. Want one? Check the folding thread!
http://zedric.no-ip.com/
Zedric is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

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