Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a program which takes input from user at rum tym..
like this
enter the string : abc1234f
and program must do calculations as ab+c1+23+4f
and return the result in two characters
Richard MacCutchan 17-Oct-14 4:44am    
This is your third question on this subject, and you have been given some answers. It's up to you to go and try them.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
Share this answer
That's pretty easy, you have to:
  1. initialize you checksum with 0, say chk=0;
  2. Take two characters at time from the input string, e.g. "ab"
  3. Convert the two characters to a unsigned char, say u using strtoul[^] with base parameter set to 16 (hexadecimal number)
  4. sum the obtained unsigned char to the checksum: chk += u;
  5. Go to point 2 unless the string is completed

It is worth nothing:
  • The sum on unsigned char discards any carry (as required by checksum algorithm)
  • You may also merge steps 2,3 possibly using your own hand crafted two-hex-characters-to-byte function
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900