Questions tagged [conversion-specifier]
120 questions
2
votes
3 answers
Format Specifier: %u vs %d in C
#include
int main(){
int a = 3;
printf("%u\n",&a);
printf("%d\n",&a);
return 0;
}
I was trying to print address of Variable, "a". Now with usage of two different format specifier, "%u" and "%d", two different memory…

RACHIT MITTAL
- 67
- 5
2
votes
3 answers
Program printing incorrect symbolic constants values
I am currently learning C and I am attempting to complete the K&R exercise 2-1. (Write a program to determine the ranges of char, short, int, and long variables, both
signed and unsigned, by printing appropriate values from standard headers and by…

Geekmeist
- 15
- 4
2
votes
2 answers
Why does scanf set the first value to 0?
I am using scanf to get an input. But when I run this code:
#include
int main(){
unsigned char in,b;
scanf("%u %u",&in,&b);
printf("%u %u\n",in,b);
return 0;
}
when I input, for example, 12 3 , the output is 0 3.
This also…

markoj
- 150
- 10
2
votes
1 answer
Format '%f' expects argument of type 'double', but argument 2 has type 'float (*)(float *)'
I am new to c and I am trying to make a calculator that asks if you want to calculate the standard deviation of a set or the average of a set. However when I run the code I get the error seen in the picture. Error screen. I don't know how to correct…

Shaun
- 23
- 3
2
votes
3 answers
Input of multiple char arrays isn't working
char toFind[100];
char replace[100];
int pos = 0;
printf("Enter a text: ");
scanf("%[^\n]", str);
printf("Enter a search pattern: ");
scanf("%[^\n]", toFind);
printf("Enter a substitute: ");
scanf("%[^\n]", replace);
pos = strnfnd(0,…

jonasPamm
- 87
- 9
1
vote
2 answers
Not able to assign 64-bit value to uint64_t in C
I have the following piece of simple C code where I simply try to assign a 64-bit value to uint64_t. However, the assignment happens as 32-bit value only and the most significant 32-bit are always zero. Not sure, what I am missing.
/*
C code :…

G Dave
- 19
- 1
1
vote
1 answer
GCC does not recognize escape character '\' on multi-line input
The below will raise compilation warning warning: unknown conversion type character ‘w’ in format [-Wformat=]
on a new version of gcc: gcc (Debian 12.2.0-14) 12.2.0
#include
int main() {
char query[4096];
snprintf(query,…

Cheetaiean
- 901
- 1
- 12
- 26
1
vote
2 answers
My program can't print a single-character string
I am trying to learn C, but for some reason my program doesn't want to print letters. It can print everything else like integers and floats just fine.
It doesn't give me an error as well, it just skips over the line where the character should be.
I…
user21414766
1
vote
1 answer
Problem while taking multiple inputs in C
I just started learning on C, I was trying to do some exercises. There is an exercise that wants me to take input for a character,a word and a sentence then print it. I tried to take all three input with scanf but when I execute the code program…

berkayyildiz
- 13
- 2
1
vote
3 answers
The times when we have to use `scanf("\n")` and `scanf("%*c")`
In C, when we use a scanf("%s") or scanf("%c") before a scanf("%s") or scanf("%[^\n]"), while giving in the input, there will be an extra '\n' at the end of the first input and that will be passed into the second input and mess up the input stream.…

Navaneeth Reddy
- 315
- 1
- 12
1
vote
1 answer
Trouble loading a csv into a struct where the last member is as an array of char
I want to read a csv file and load it into an array of struct. I used the code that I found on youtube and github (https://github.com/portfoliocourses/c-example-code/blob/main/csv_to_struct_array.c). Now I want to change all the members of the…

ecjb
- 5,169
- 12
- 43
- 79
1
vote
2 answers
Difference between "%i" and "%d"
What is the difference between "%i" and "%d" in the scanf function, are they same or different? In printf, "%d" is used to print an integer value, so is the use of "%i".

Haider Shah
- 11
- 3
1
vote
1 answer
Difference between " %[^\n]%*c" and " %[^\n]" for consecutive scanf in C
I've been trying to scanf multiple consecutive strings.
I know you have to eliminate the newline character and i've also been told that "%[^\n]%*c" is the RIGHT way.
But in my tests, " %[^\n]" works even better because it's simpler and also doesn't…

Cristian Lukaszewicz
- 13
- 2
1
vote
3 answers
printf: why doesn't %x print leading 0x (as opposed to %a)?
This code:
#include
int main(void)
{
printf("%a\n", 1.0);
printf("%x\n", 93);
}
outputs:
0x1p+0
5d
Why not 0x5d?
Does someone know the rationale?
Note: this question is not exactly the same since it is about %#x.
Reason of the…

pmor
- 5,392
- 4
- 17
- 36
1
vote
2 answers
sscanf does not work properly for eight and nine with leading zero
I've been trying to scan integers with sscanf() from strings with leading zeros (e.g. '03').
However, it works fine but only until '07'. Starting with '08', the strings will be read as 0.
Below you'll find my code and the output. Thank you for your…

stulli
- 21
- 3