Chars - ints

This is a discussion on Chars - ints within the C Programming forums, part of the General Programming Boards category; I am reading the first character from a file as a char, but it is an integer. I am using ...

  1. #1
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198

    Chars - ints

    I am reading the first character from a file as a char, but it is an integer. I am using fgetc, to read it in, and now i want to get the that char i read, and assign it a new name, but not as a char, but as an integer.

    Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    fgetc returns an integer. However, the value is going to not be 1 if you in fact read a '1' from the file. Do something like:

    x = fgetc( fp );
    x = x - '0';

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    thanks!!!!! I got it to work!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2009, 10:37 AM
  2. A lottery program - arrays, ints, chars etc
    By Glauber in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2008, 11:48 AM
  3. converting ints to chars
    By e66n06 in forum C Programming
    Replies: 4
    Last Post: 07-28-2007, 04:52 PM
  4. Carrying ints a chars over to other functions.
    By jmajeremy in forum C++ Programming
    Replies: 39
    Last Post: 04-04-2007, 07:17 PM
  5. atoi not converting chars to ints?
    By C++Child in forum C++ Programming
    Replies: 13
    Last Post: 10-08-2004, 04:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21