Thread: Int and Chars

  1. #1
    Deleted Account
    Join Date
    Mar 2005

    Int and Chars

    Ok, I'm not sure exactly how to explain this but I'll try my best...

    1. a function passes an unsigned in the form functionName(unsigned number)

    2. I store it in an integer, i.e. int store = number; (and say number is: 1965)

    3. I convert it to char-> char converted[5];
    sprintf (converted, "%d", store);

    My question is I want to seperate say 19 from 1965 and store it in an integer, and 65 in another integer, how do i go abouts. BTW, I'm thinking there would be a more direct way than doing all these conversions? Thanks

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Here's a hacked together c++ example

    #include <iostream>
    using namespace std;
    int main()
    	int a = 1965;
    	int b, c;
    	b = a % 100;
    	c = (a-b) / 100;
    	cout << c << " " << b << "\n";

  3. #3
    Deleted Account
    Join Date
    Mar 2005
    Ok, thanks alot, didn't think of that ...

    anywayz, I just realised what I'm doing wouldn't work. I tried it on pen+paper but yea, it only works with 4 digits..and I can't figure it out with less..

    This is my scenario, to work out the century when you input a year but I don't even noe how the centuries etc supposedly 2005 is 20th century on the website, so I'll stick to that for the moment.

    Zeller's Rule:
    f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.
    D is the last two digits of the year
    C stands for century:

    I wonder if the formula works for years from 0 - 9999...

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > I wonder if the formula works for years from 0 - 9999...
    Well since there was no year 0, and that calendars changes from Julian to Gregorian at various times in various places, then answer is no.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM