'C' Programming (CS215)

Mainframeguy said:
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 :eek::)
Do you really think a course with this assignment would care about cross platform portability? ;)

Nevertheless, good point.
 
Zedric said:
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
 
Mainframeguy said:
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
 
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
 
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)    [I]<-- Wrong number of parenthesis and -1 isn't really needed if you use <= 0 instead[/I]
    return 0;
  else
    if(intarr [size]>0)    [I]<-- Wrong element (gives error on first attempt) plus I don't know if the space is allowed before [][/I]
      sum=sum+intarr[size-1]    [I]<--- Missing ;[/I]
  return sum+AddPos(intarr, size--)    [I]<--- Missing ;[/I]
}
 
CHiLLaXen said:
Zedric: you shouldn't give him all the answers, just give him some hints :p
Did I? At least I didn't give him compilable code. ;)

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

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back