top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How we can write hexadecimal value in a string?

0 votes
523 views
How we can write hexadecimal value in a string?
posted Jun 23, 2017 by Priya Kanojiya

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Use %x inside printf but still I am thinking that my answer is doubtful as you are saying it to write in a string form.
You can build a char array by using this method or try to 0x before %x in printf.
Simple example based on a character:

#include <stdio.h>

int main(void) {
    // your code goes here

    printf("0x%x", 15);
    return 0;
}

output: 0xf
Online link: https://ideone.com/opLXV8

answer Jun 26, 2017 by Shivam Kumar Pandey
+1 vote
#include<stdio.h>
#include<string.h>
main()
{
        int a;
// Printing address of a which is hexadecimal value
        printf("Address of A = %p\n",&a);
        char str[100];
// Storing address of a inside character array(string)
        sprintf(str,"%p",&a);
// Printing string
        printf("STR = %s\n",str);
}
answer Jun 27, 2017 by Chirag Gangdev
Similar Questions
+5 votes

Can we realloc a string inside a structure?

struct info
{
     char name[20];
     int age;
     char address[20];
}; 

struct info d[10];

I want to realloc name, how can I do it?

+2 votes

Assumption:
The input strings will contain only numeric digits
The input strings can be of any large lengths
The lengths of the two input string need not be the same
The input strings will represent only positive numbers
Example

If input strings are “1234” and “56”, the output string should be “1290”
If input strings are “56” and “1234”, the output string should be “1290”
If input strings are “123456732128989543219” and “987612673489652”, the output string should be “123457719741663032871”

+2 votes

Output
Enter the string: Welcome to C Class!
Enter the word to insert: programming
Enter the position you like to insert: 3
The string after modification is

Welcome to C programming Class!

...