All pastes #446378 Raw Edit

bisio

public c v1 · immutable
·published 2007-04-18 13:14 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <readline/readline.h>#include <readline/history.h>static char *line_read = (char *)NULL;union an_union {  int an_integer;  float a_float;  double a_double;  long a_long;} u;void load_in_u_swapped(char *line_read){  int i=0;  int count=0;  int temp[8];  unsigned char *pointer = (unsigned char *) &temp;  unsigned char *u_pointer= (unsigned char *) &u;    while (i<strlen(line_read))    {       sscanf(&line_read[i],"%x",&temp[count]);       i+=5;       count++;    }  count--;  for(;count>=0;count--)    {      pointer=(unsigned char *) &temp[count];      strncpy(u_pointer,&pointer[0],1);      u_pointer++;    }}void load_in_u(char *line_read) {  int i=0;  int temp=0;  unsigned char *pointer = (unsigned char *) &temp;  unsigned char *u_pointer= (unsigned char *) &u;  while (i<strlen(line_read))    {      sscanf(&line_read[i],"%x",&temp);      //printf("%d\n",pointer[0]);      strncpy(u_pointer,&pointer[0],1);      i+=5;      u_pointer+=1;    }}char * rl_gets (char *prompt){  /* If the buffer has already been allocated,     return the memory to the free pool. */  if (line_read)    {      free (line_read);      line_read = (char *)NULL;    }  /* Get a line from the user. */  line_read = readline (prompt);  /* If the line has any text in it,     save it on the history. */  if (line_read && *line_read)    add_history (line_read);  return (line_read);}void parse (char *line_read){}int main (int argc, char **argv){  char *prompt=NULL;  char *prompt1="hex:le> ";  char *prompt2="hex:be> ";  prompt=prompt1;  while (1)    {            line_read=rl_gets(prompt);      //printf("%s\n",line_read);      load_in_u(line_read);      printf("int=%d\n",u.an_integer);      printf("float=%f\n",u.a_float);      printf("double=%f\n",u.a_double);      //prompt=prompt2;    }  return 0;}