#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( int argc, char *argv[] )
{
char *string = argv[1];
int i;
char* p = string;
for (i=0; i<strlen(string); i++)
{
int c;
for (;p[0] && p[1] && sscanf(p, "%2x", &c); p += 2) printf("%c", c);
}
printf("\n");
}
This code works fine when passing an arguement(Hexadecimal) and produces a string. I need the same as a function; when passed a hexadecimal value gives a string.
I tried using a function but there's no output.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int fun (char * s)
{
char *string = s;
int i;
char* p = string;
for (i=0; i<strlen(string); i++)
{
int c;
for (;p[0] && p[1] && sscanf(p, "%2x", &c); p += 2) printf("%c", c);
}
printf("\n");
}
int main()
{
fun("Hello");
}
PS: Please go easy on me. I'm new to this.