Questions tagged [conversion-specifier]
120 questions
-1
votes
1 answer
Reading an integer, one digit at a time
I have seen the following code work:
int d1, d2, d3, d4, d5;
printf("Enter group of five digits: ");
scanf("%1d%1d%1d%1d%1d", &d1, &d2, &d3, &d4, &d5);
But the following code fail:
int ar[5], counter = 0;
printf("Enter number: ");
while(counter <…

kchak
- 7,570
- 4
- 20
- 31
-1
votes
3 answers
Why does this *ptr NOT give the actual value stored at the memory address contained in ptr variable?
Here is a basic C program about pointers:
#include
int main() {
int variable = 20;
int *pointerToVariable;
pointerToVariable = &variable;
printf("Address of variable: %x\n", &variable);
printf("Address of variable:…

Shy
- 542
- 8
- 20
-2
votes
2 answers
How to print two strings on the same line in c using printf
I am trying to print the out put of name and phone. Keeps showing this two errors in terminal
format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’
and
format ‘%s’ expects argument of type ‘char *’, but argument 3 has type…

wanicedude
- 17
- 1
-2
votes
3 answers
C pointer format displaying useless characters
When trying to print a pointer, for example
#include
main() {
int a = 3;
printf("The address : %p\n", &a);
printf("As an hex : %x\n", &a);
return 0;
}
I get a 000000ac4f5ffd58 and the nice 4f5ffd58 (the first two…

DiraD
- 15
- 4
-2
votes
2 answers
Pointers with multi dimensional arrays in C
int array[2][3] = {{2,3,6},{4,5,8}};
printf("%d\n",*array);
What will be the output of this and please explain how?
Regards,
Winston

winstonbrown
- 70
- 1
- 6
-2
votes
2 answers
How do i use pointer as parameter
I write something to get famliar with pointer.
void print_line(int64_t number, char *string)
{
(void)number;
(void)string;
printf("%d %s \n", number, *string);
return;
}
int main()
{
print_line(42, "Hello World!");
…

tcx
- 1
-2
votes
2 answers
When I going to print a hexadecimal value using printf it takes the input as decimal value why?
For example
printf("%x",16);
This printf prints 10 instead of 16 why it is not take the value as hexadecimal pls someone explain this

Muneesh
- 21
- 4
-2
votes
3 answers
Why printf is not able to handle flags, field width and precisions properly?
I'm trying to discover all capabilities of printf and I have tried this :
printf("Test:%+*0d", 10, 20);
that prints
Test:%+100d
I have use first the flag +, then the width * and the re-use the flag 0.
Why it's make this output ? I purposely used…

Sadek
- 175
- 1
- 7
-3
votes
3 answers
A beginner question about the return value of the C ternary operator
Consider this code:
#define SZIE 1024
printf("%\zu",SZIE<-1?1:0);
It will print '0'.
This confuses me.
In my view, the signed number -1 shoulkd be converted to SIZE_MAX.
The expression 1024 < SIZE_MAX is true, so I think "1" should be printed, but…

cy1
- 1
-3
votes
1 answer
Why isn't my integer printing out properly in C
I am trying to just write something that takes a month and date and prints it back out. I have written the following code:
int main(void){
char month[] = {};
int day;
printf("Please enter the month and day of you date. i.e January…

Scott Roan
- 17
- 3
-3
votes
1 answer
In C, how to fix this warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)[100]
How to fix the warning?
warning: assignment to ‘struct people *’ from incompatible pointer type ‘char *’
format ‘%s’ expects argument of type ‘char ’, but argument 3 has type ‘char ()[100]
/* loading user information from the file*/
void…

Taja
- 9
- 4
-3
votes
1 answer
How to resolve GCC compilation [-Wformat] warning?
I am using this approach to convert hex string to byte array.The code is works correct.
While compiling this code I am getting below compilation warning. Is there any way I can resolve it?
/* test.c */
#include
#include
#include…

raj123
- 564
- 2
- 10
- 27
-3
votes
6 answers
When printf a string we are not using *. Why?
In c programming when we print a string. We are not using * . But when print a number using printf we are using *. So how it is understanding, i am printing a string or int. Is understanding using %s operator?
Attaching an example…

Vipin
- 938
- 5
- 18
- 36
-4
votes
2 answers
How can I take a few chars and print it as a one word
I need help in C, I need to build a software that takes from the user (input) 3 chars and then print it as a word.
For example the user enters:
A
B
C
then the software should print ABC.
I tried doing it on this method:
printf("%c %c…
-5
votes
1 answer
What (%f) means in C?
I know that %f means float, althought, I don't know if the brackets make any difference.
I have this:
void print_LIST(LIST L){
CORD *c;
while(L != NULL){
c = L->value;
printf("%d%d",c->col,c->lin);
printf("(%f)…

unstablespartan
- 39
- 3