Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,872 questions

51,796 answers

573 users

How to convert array of hex strings to int and char in C

2 Answers

0 votes
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char hexarr[][3] = { "61", "7A", "20", "0A", "49" };
    int i, n;
    
    for (i = 0; i < sizeof(hexarr)/sizeof(hexarr[0]); i++)
    {
        n = (int)strtol(&hexarr[i][0], NULL, 16);
        printf("%d - ", n);
        printf("%c\n", n);
    }    
   
    return 0;
}

/*
run:
  
97 - a
122 - z
32 -
10 -

73 - I

*/


answered Mar 19, 2015 by avibootz
edited Mar 19, 2015 by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char hexarr[][3] = { "61", "7A", "20", "0A", "49" };
    int i, n;
    
    for (i = 0; i < sizeof(hexarr)/sizeof(hexarr[0]); i++)
    {
        sscanf(&hexarr[i][0], "%x", &n);
        printf("%d - ", n);
        printf("%c\n", n);
    }   
   
    return 0;
}

/*
run:
  
97 - a
122 - z
32 -
10 -

73 - I

*/


answered Mar 19, 2015 by avibootz

Related questions

1 answer 85 views
2 answers 83 views
83 views asked Dec 2, 2024 by avibootz
1 answer 87 views
1 answer 117 views
1 answer 116 views
1 answer 165 views
...