Thread: converting chars to ascii equivilant

  1. #1
    Unregistered
    Guest

    Question converting chars to ascii equivilant

    How do I convert characters (in arrays and strings) to its respective ascii value. I want to do that so I can encrypt some variables for a save file, to prevent tampering(or at least not useful tampering). Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    how do you think they are stored in memory??

    as characters?
    remember computers only understand numbers!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    1
    Stoned_Coder is right.

    But for knowledge sake, use the stty raw echo command. Get the input and the raw echo will convert it to hex.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void main(){
    
       
       char input;
       system("stty raw -echo");
    
       printf("This program is designed to convert characters into hex"
          " value\n\r");
       printf("Press q at any time to quit this program");
       while(input != 'q'){
          fflush(stdin);
          printf("\n\rPlease enter a character:");
          scanf("%c", &input);
          printf("\n\rChahrater entered:	%c", input);
          printf("\n\rHexidecimal value:	%x", input);
          printf("\n\n\rPress q at any time to quit this program");
    
       }
       printf("\n\r\n\rThank you\n\r");
          system("stty -raw echo");
    }
    This is just a little C that I put together for you...lol Just to test that conversion works......printf. Object oriented is pretty much the same way.


    But this will not make anything secure!!!

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Or you could use itoa

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. converting ints to chars
    By e66n06 in forum C Programming
    Replies: 4
    Last Post: 07-28-2007, 03:52 PM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Converting ascii to integer without using atoi
    By sansuki in forum C++ Programming
    Replies: 9
    Last Post: 03-30-2005, 07:38 AM
  5. converting a string to it equivalent ascii value
    By pauljhot in forum C Programming
    Replies: 12
    Last Post: 02-16-2002, 02:35 AM