Questions tagged [conversion-specifier]
120 questions
0
votes
3 answers
Incorrect result when using %d placeholder in a pow() function in C
I'm trying to finish some basic coding exercise and I have already figured out how to fix it but I would just really like to understand what's going on.
#include
#include
int main(void) {
int first, second, third, fourth,…

ddp17
- 41
- 4
0
votes
2 answers
What is the use of scanf("\n"); statement before scanf("%[^\n]%*c", s)?
What is the use of scanf("\n"); statement before scanf("%[^\n]%*c", s) ?
int main()
{
char ch;
char str [100];
char s[100];
scanf("%c",&ch);
printf("%c",ch);
scanf("%s",&str);
printf("\n%s",str);
scanf("\n"); …

MAHAVISHNU G
- 1
- 1
0
votes
2 answers
Differing output with printf using %d and %i
I found questions about %i and %d on here, but all of them seemed to claim that they were the same in printf.
Compiler: Apple clang version 12.0.5 (clang-1205.0.22.9)
Note: 15 is 017 in octal and 0xf in hexidecimal.
I was previously under the…

Clay Smith
- 19
- 7
0
votes
2 answers
What data types in C language are these variables and where I am wrong?
Now I am learning the C language and I have two tasks. Define variables and print them Here is my code:
#include
int main()
{
printf("Excersise 1\n\n");
int cVarOne = -250;
int cVarTwo = 250;
int cVarThree = 4589498;
…

doubleU
- 1
- 2
0
votes
1 answer
What does "%%%ds" mean in a c program formatting text?
This c code I wrote below to centre text in strings works.
I cannot find an explanation of what "%%%ds" in the program means and how it works.
There is d for int and s for string but the three percentage symbols is obscure to me.
What does "%%%ds"…

currawong
- 23
- 3
0
votes
2 answers
Default element value is used instead of user defined in C?
I am beginner in C. I have been writing a program code to find largest element in Array.
Passed Value is not able to store in array of type: float.
Instead default Value:0 is being stored.
What to do?
#include
// Largest Element
int…

RACHIT MITTAL
- 67
- 5
0
votes
1 answer
This is another example of my neverending confusion related to memory and pointers in C
I am a newbie in C, but I have already watched dozens of videos on YT about how to understand pointers... Unfortunately, it seems my stupid brain is not getting the point about pointers. Could anyone help me to understand why I am getting such…

Tom
- 11
- 4
0
votes
1 answer
Printf is not working properly after a new line character
I was trying to make an AYAYA pyramid program in C just because I noticed that the 'A' and 'Y' fits really well togheter and the 'A' can also be the top of the pyramid.
The program works, but then I wanted to create a small introduction to the…

Fuffi
- 1
- 2
0
votes
2 answers
Why are there garbled characters in this C program output?
#include
#include
#include
int main() {
// setlocale("LC_ALL","");
unsigned char utf[]={0xe4,0xb8,0x80,0x0a};
printf("%s",utf);
return 0;
}
The first four bytes of output are correct. The second line…

user8911572
- 13
- 3
0
votes
1 answer
why can't I input a character with scanf
why is this not working? im new to C...
the scanf function works just fine with other data types, its just the char thats not giving me the option to input a character
char grade;
printf("Enter your grade: ");
scanf("%c", &grade);
printf("Your grade…

hikkichuu
- 1
- 1
0
votes
1 answer
How to align tabular data to the left with printf?
Let us suppose that we want to display different values aligned in a tabular way, in C, using printf.
We can do something like this:
#include
int main()
{
char strings[5][10] = {"Test1","Test2","Test3","Test4","Test5"};
int ints[5]…

Zaratruta
- 2,097
- 2
- 20
- 26
0
votes
3 answers
Difficult time understanding string pointers in C
I am looking to learn C and having a really hard time grasping the concepts of string pointers (and just pointers in general).
I have the following program:
#include
#include
int main()
{
// char test[6] = "hello";
…
0
votes
3 answers
why this is not giving correct output while this is working on c++
when I write this code in c it does not work but when I make few changes like replacing with cin and cout it works fine in c++
#include
#include
int main()
{
int i=0,l,m;
char str[10],c;
…
0
votes
5 answers
type casting in C doesnt change 97 to 'a'
#include
int main(){
printf("%d\n", (int)('a'));
printf("%d\n", (char)(97));
}
Why does the program above give the output
97
97
instead of
97
a

Matthias
- 1
- 1
0
votes
1 answer
What are the fractional octal and hexadecimal conversion specifier in C?
I am aware that when using the printf function I can express the octal value of an integer with %o and its hexadecimal value with %x.
How can I represent a floating-point value as octal or hexadecimal, though?
When trying to use the same specifiers,…

NotationMaster
- 390
- 3
- 17