Format Codes in my function [closed] - c

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 years ago.
Improve this question
In C/C++, is there a way to write my function so that I can use format codes to print information easier? The function draws text to the screen with SDL, so I can't pass in a C++ string; it has to be a char array.

Firstly, you can convert a c++ string to a char array using myString.c_str().
Also, you can use sprintf() with format codes to produce a string. Then you can draw that string using SDL. For example:
char myString[1024];
sprintf(myString, "Hello my name is %s", "foo");
draw_using_SDL(myString);

Related

Printing space between strings when using strcat() function [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 6 years ago.
Improve this question
How to print a space between two strings using strcat() function in c language?
You can do something like this.
strcat(string1, " ");
strcat(string1, string2);
or, just in one line.
strcat(strcat(string1, " "),string2)
Both the snippets are actually same!

How to read multiple lines in string until specified character 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 6 years ago.
Improve this question
Need to read everything until say *** comes up:
Input:
Hey there
how are
you
***
Output:
Hey there
how are
you
Would have used scanf("%[^***]s) but can't read all lines at once.
Only having basic C knowledge
The way I would do this is read one line at a time (with a funcion such as fgets instead of scanf) and then see if the line that you last read is equal to ***. You can use use strcmp to do that but you can also do it by hand if you are not allowed to use strcmp for some reason.

Character functions vs string functions [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 6 years ago.
Improve this question
I just found a short code here, which would detect blank lines in a file. It used fgets() function in C library.
I wonder if character functions are better suited for files which have tabs, and perhaps continous spaces.
My qustion is what is the best way to parse a file for blank lines?
You can also use scanf(" %[^\n]s",string); in order to read spaces but fgets is best solution for your case.

Displaying pointer's address in C, without using printf? [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 6 years ago.
Improve this question
I need to recode the printf function using only a handful of functions from the libc library, namely write, malloc and free and a few other basic ones. The only formatting tab that I am having trouble with is %p as I have no idea how to display it using the write function, as passing the address of my pointer to a function that prints strings resulted in empty output. I have also tried typecasting it to a char * and unsigned char * but that did not work either. I have looked online but only found solutions invloving forbidden functions so I am not even sure where to begin.

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.)

Resources