reading long hexadecimal integer

This is a discussion on reading long hexadecimal integer within the C Programming forums, part of the General Programming Boards category; Does anyone know if you take an 16 character hexadecimal input ie 1234567890abcdef and read it into two unsigned long ...

  1. #1
    Unregistered
    Guest

    Question reading long hexadecimal integer

    Does anyone know if you take an 16 character hexadecimal input

    ie 1234567890abcdef

    and read it into two unsigned long integers variables key1 and key2 such that

    key1=12345678
    key2=90abcdef

    in other words how can you get computer to read first 8 hex characters of input and assign to unsigned long int and then read the next 8 hex char and assign to other unsigned long int.

    Thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    This is a bit dirty, but it does the job
    (it needs some error checking too).

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	char buffer[BUFSIZ];
    	unsigned long l1, l2;
    	printf("Enter 
    	if (fgets (buffer, 9, stdin) != NULL)
    	{
    		sscanf(buffer, "%x", &l1);
    		printf ("%ld\n",l1);
    	}
    	
    	if (fgets (buffer, 9, stdin) != NULL)
    	{
    		sscanf(buffer, "%x", &l1);
    		printf ("%ld\n", l1);
    	}
    	
    	return(0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Replies: 6
    Last Post: 10-08-2008, 05:51 AM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 12:30 PM
  5. Reading an unsigned long from a file
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 08-26-2001, 01:19 PM

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