Converting an int to string without using library functions in C? [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 8 years ago.
Improve this question
How do you convert an int to a string without using library functions in C?

You can achieve this by extracting each bits one by one, like this
str[i] = (char)( (num % 10) - 48 )
48 has to be subtracted because an integer value changing to character goes through an ASCII conversion. Keeping the above line in a loop, that would run for each digit in the number, should do the trick..

Related

Power of any number program in c language [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 9 days ago.
Improve this question
How can write a code for power of any number in c language in program I have given base & exponent using for loop then inside for loop define power=power*base &then print base, exponent

working of these two lines of code in the program [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 4 years ago.
Improve this question
total+=!used[str[i]-'a'];
used[str[i]-'a']=1;
It is the condition for checking the characters and saving the value in the variable total.
The total variable will contain the number of unique characters in the array str.
This happens because you increment the count(total+=!used[str[i]-'a']) only if you haven't already marked the character as visited. If you incremented it, you mark it as such in the next line (used[str[i]-'a']=1) so that you wont count it again.
The notation str[i]-'a' is used to shift the ascii values of the characters from 0 to 25 (instead of 97 to 122) so that you can spare some space in the array.

How we can sort numbers lexicographically without converting them to strings in C language? [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 5 years ago.
Improve this question
I have tried to sort the numbers using dictionary sort with converting them to strings.But I don't know how to sort numbers using dictionary sort without converting them to strings
Find the largest power of 10 (the number of digits of your biggest number)
Write your compare function so it does a comparison between
a * 10 ^ (max_digits - a_digits) and b * 10 ^ (max_digits - b_digits)
Apply any sort algorithm you wish with this comparison function.

Printing char values in hex inside a 1-character square in C? [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 7 years ago.
Improve this question
In C, is it possible to force an unsigned char to print as a hex, not with %x, but in the little square box that displays the four hex numbers, but only takes up one character, for example 轩?
No, it is not possible.
This is not related to C, but to the font your terminal uses. C outputs characters as bytes; your terminal is responsible for choosing how to display them as pixels. (You might as well ask how to make the text italic.)

What does this piece of c code do? [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 came across this piece of code, but am not able to entirely make sense of it:
(((x)[y] << 8) | (x)[(y)+1])
where x is a pointer to a const unsigned char and y is an integer.
It extracts the 16-bit big-endian value starting at index y from array x.

Resources