I'm trying to learn some of the basics of C and I have been reading nonstop about gets/fgets/puts/scanf and can't seem to get this right...
My code is:
#include <string.h>
#include <stdio.h>
#define BUFF 256
void main()
{
char s[BUFF];
fgets(s, BUFF, stdin);
s[strlen(s)-1]='\0';
printf("%x %s %d", s, s, strlen(s));
}
I'm trying to get the hex format of the variable s to print, my input is AAAA and the output I want is 41414141 AAAA 4, the output I'm getting is 12fe80 AAAA 4.
I thought I needed to cast s (as a u int) for the hex interpretation, but that didn't work either.
I would really appreciate an explanation on this as well as help, I'm really trying to learn this.
Thank you!