• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

'C' Programming (CS215)

dal2lad

OSNN One Post Wonder
#1
'C' Programming HELP

Hi,

Any voluntier to help me in my 'C' Programming ?

The Question:

The fuction below needs to be run in a program.

Write a fuction called ChangeToNext that take in an uppercase character parameter ch. The function returns the next upercase character if ch is between 'A' and 'Y'. If ch =='Z', the function returns 'A'. You may assume that the character parameter ch is always an uppercase alphabetic character.

Thank you
 
#2
That question is very straight forward. If you can't solve it I suggest you read up on what you're supposed to do. I could write it for you, but what good would it do?

At least give it a try. If you can't get it right, post back with what you have and well try to see what's wrong with your code. Good luck! :)
 

X-Istence

*
Political User
#4
This is simple to write. Just a hint:

char blah = 'A';
int num = blah;

prinft ("%d", num);

Should print a number, not the character A. Use this to your advantage, as

char B = (int)A + 1;

So all you really need to check, is if it is Z before you do that, and if it is Z, then set char equal to A.

Damnit, allready gave you to much info. Good luck.
 

Mainframeguy

Debiant by way of Ubuntu
#7
/me wants to see the code ;) damn it this is so much like stuff I do in machine code - I love seeeing thing stuff in C and laughing when it is the same # of lines as my assembler (well - nearly!)
 
#17
X-Istence said:
Not everyone knows that off the top of their head :p
quite true, like my Networks and Communications lecturer for example, though it was more odd when he said that lower case started at 41 and upper case started at 61

i mean you can just think about that and know its wrong, theres only 20 characters between 41 and 61, so not enough space. But then he was right about where the upper case started, well close enough :p
 

Mainframeguy

Debiant by way of Ubuntu
#18
Geffy said:
quite true, like my Networks and Communications lecturer for example, though it was more odd when he said that lower case started at 41 and upper case started at 61

i mean you can just think about that and know its wrong, theres only 20 characters between 41 and 61, so not enough space. But then he was right about where the upper case started, well close enough :p
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 ;)
 

Mainframeguy

Debiant by way of Ubuntu
#19
FishBoy said:
He doesn't really need ASCII table coz he's only going to work from A to Z which is 65 to 91
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::)
 
#20
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 ;))
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies