Thread: about testing a program

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    28

    about testing a program

    Hi,

    I was working on a program convert 16-HEXA-character key to be 8-ASCII-character key. apparently I am having problem for testing it because it producces strange symbols it also uses an auxilary program that converts Hex value into decimal.

    Can anyone see if the way I am testing the program is correct ?

    Code:
    code
    
    
    int main()
    {
       int i;
       ByteType y;
       ByteType X [16] = "FFFFFFFFFFFFFFFF";
       for( i = 0 ; i < 16; i++)
       {
           y = ASCIZ( &X[i]) ; 
           printf("the corresponding characters are %c\n", y);  
        }
    
    }     
    
    ByteType ASCIZ(ByteType *Addr)
    {
    	int i, v1, v2;
    	ByteType a1, a2, v;
    
    
    	/* Convert 16-HEXA-character key to be 8-ASCII-character key. */
    	for (i = 0; i < 8; i++)
    	{
    		a1 = *Addr++;
    		if (i == 7)
    			a2 = *Addr;
                                    else
    			a2 = *Addr++;
                         /* Convert two HEXA characters into their decimal value. */
    		v1 = Convert(a1);
    		v2 = Convert(a2);
    
    		/* Convert the two decimal value to be one ASCII character. */
    		v = ((v1 * 16) + v2);
    	}
    	
    	  return   v;
    }
    
    
    
    /* there is function that converts Hex to decimal */
    int Convert(ByteType val )
    {
       if ((val >= 0  ) && (val <= '9' ))
            
          return val;           
       
       else ...
     
    }

  2. #2
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226
    For easy conversion to-and-from b/w number systems...use

    char* itoa(int value, char *string, int radix);

    where radix = number system (e.g. 16 for hex,8 for octadeci, 10 for ...)

    for further info. see your nearest online help...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 09:12 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM