What does the character "%XX" mean in C language? [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm having trouble finding what does %XX mean in C
an example would be like: printf("%XX\n", num);
edit: num is an int

print num converted to unsigned int as a hexadecimal number and then print char 'X'

In a printf format string, %XX is %X followed by X.
The %X says to format an unsigned int argument as hexadecimal, using uppercase (ABCDEF for the “digits”).
The X is simply a literal X that says to print an “X” after the hexadecimal numeral.

Related

Convert hex String to decimal string in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
How would you convert a hexadecimal string, like "661efdf2e3b19f7c045f15" to the decimal string "123456789123456789123456789"?
Thanks in advance!
Using GMP you can assign the hex number to an "mpz_t" the GMP integer value. Here's an example.
#include <gmp.h>
int main(int argc, char** argv) {
mpz_t integer;
mpz_init(integer);
mpz_set_str(integer, "661efdf2e3b19f7c045f15", 16); //16 is the number base
gmp_printf("Your number is: %Zd\n", integer); //Outputs "Your number is: 123456789123456789123456789"
return 0;
}
GMP comes automatically with some linux distros but if you don't have it, you can download it here.
Hope this helps!

assign zero to item in char array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I have some materials showing this code. what does code means by making these assignments?
char inputfilename[128];
inputfilename[0] = 0;
char *argv[128];
*argv[1] = 0;
In C, character arrays are terminated by a null character (value 0). In both cases in your example, the code initializes the strings to "empty" (with a terminator in the first element). This would prove useful in any subsequent string operations (strcat, strcpy, etc.).

Need to understand this If statement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I need to understand more about this if condition the two sides of comparison and how it is compared:
int main()
{
unsigned short i;
if (i == '9' * 256 + '5')
{
/* Do stuff */
}
}
How are these compared?
Formally the behaviour of your code is undefined as you are reading the uninitialised variable i.
'9', 256, and '5' are all int types in C. So the right hand side is evaluated in int arithmetic, with the potential for overflow (it will not overflow with ASCII encoding).
i will be converted to an int type prior to the comparison.

I am finding difficulties to solve an expression [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am finding difficulties to solve an expression please help me to do so.
Declare four variables of type char. Initialize one variable to ‘z’. Initialize the other variables to the ASCII integer value for ‘z’, the ASCII octal value for ‘z’, and
the ASCII hexadecimal value for ‘z’.
Just declare a char variable and assign the value. To assign hex prefix with 0x, for octal use 0 and for decimal just write the number with no prefix.
The decimal ascii value of 'z' is 122.
#include <stdio.h>
int main() {
char a = 122;
char b = 0x7a;
char c = 0172;
char d = 'z';
putchar(a);
putchar(b);
putchar(c);
putchar(d);
}
All these char variables have the same value so four zs will be printed.

Reading lines of a float and converting to integers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Write a C program that reads lines containing floating point values of type double one per line from the standard input ( e.g. using scanf ), converts those values to integers and then prints those values as right justified integers in a 20-character wide field one per line on the standard output.
#include <stdio.h>
My biggest problem is I don't know where to start. Any tips and help would be appreciated.
The concept is to TYPECAST the float to an integer.
The loop here is for multiple values if you want.
This is the program. I hope this helps; it runs as you want.
#include <stdio.h>
int main()
{
float n;
int t;
//loop here
scanf("%f", &n);
t = (int)n;
printf("%20d", t);
// end loop here
return 0;
}

Resources