I'm trying to write a program that will take as an input a string of characters and output their hex representation.
i decided to start off by writing a program that takes in one input character and outputs its hex representation, and it worked. Code below:
then I tried to take it to the next step by having my program understand a string of characters and output its hex characters, here is my attemp:Code:
#include <stdio.h>
main()
{
int i;
i=getchar();
printf("its hex character is %3x\n", i);
}
as you can see maybe I'm trying non-sense but I tried to define a char line(maximun number of bits to be 100). then I wanted the input line typed by the keyboard to be placed in the string to be printf as a '%s' string of character is hex format. Any help would be appreciated it, hence this is basically my first program, i am trying to write to learn this languageCode:
#include <stdio.h>
#define MAXLINE 100
main()
{
int i;
char line[MAXLINE];
line[i] = getchar ();
printf("%s, its hex character is %3x\n", i);
}
elrookie