Questions tagged [conversion-specifier]

120 questions
1
vote
3 answers

What exactly does this format string do when paired with fscanf?

I am looking at some code and came across this line: fscanf(file, "%*[: ]%16s", dest); What does the %*[: ]%16s format string specifier do?
1
vote
2 answers

warning: format ‘%f’ expects argument of type ‘float ’, but argument 2 has type ‘double ’

everyone. I NEED HELP! I was trying to submit this following HackerRank's challenge : Task Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal…
Cyclone
  • 25
  • 7
1
vote
1 answer

C ascii converter printf Extra integer

Trying to create a simple C char to ASCII convertor But the result print "10" after each printf. Any Ideas to resolve that? Compiler: mingw64/gcc Source: #include #include #include void main() { char argc; …
ycohui
  • 66
  • 7
1
vote
1 answer

C Input won't add to array list

The 2 arrays wont store input, the increment of each index number is always at 0 as printf states it. int main() { int ingredientsAmount; double ingredientsPrice[10]; double ingredientsWeight[10]; scanf("%d", &ingredientsAmount); …
I Y S Z
  • 45
  • 5
1
vote
4 answers

Unable to read the char input in C using %c

#include #include int main() { int num1; int num2; char op; printf("Enter the first number: "); scanf("%d", &num1); printf("Enter an operator: "); scanf("%c", &op); printf("Enter the second…
1
vote
1 answer

How to fix warning "Format specifies type 'void *' but the argument has type 'char' warning"

I am getting the output that I want but can't figure out how to get rid of these warnings. Any help is appreciated. Warnings: Format specifies type 'void *' but the argument has type 'char' [-Wformat] printf("\nThe pointer variable's value is…
SimTim124
  • 51
  • 5
1
vote
1 answer

Why is my program skipping the 2nd scanf line?

I had this problem for a while. when I try to run my program, It will run but it will skip the 2nd scanf which is the nudoor, the part where my program ask for number of doors. If anyone could help. Here's the screenshot of my program running DOOR…
Meowtyx
  • 13
  • 2
1
vote
2 answers

Casting double to int works with constants only

I found a strange (to me) behavior of casting to int in C. Appologies if that's a basic question but I'm unable to find the answer to why the following code produces an unexpected result. #include int main(void) { printf("1000 * 0.1 =…
kiler129
  • 1,063
  • 2
  • 11
  • 21
1
vote
3 answers

How to create a char* substring of a char* string in C?

I want to create a substring, which I see online everywhere and it makes sense. However, is there any way to, instead of outputting to a regular array of characters, output the substring as a char* array? This is the idea of my code: char *str =…
Ryan237
  • 17
  • 3
1
vote
1 answer

variable is not being evaluated and skips if statement c

I have a question. When I try to ask a user to enter yes or no as a single character and set the char variable with brackets as I either get that Y or y is not valid in my if statement. If I do it without brackets I only get the ascii value which…
Jose Ortiz
  • 705
  • 1
  • 9
  • 19
1
vote
2 answers

Usage of zd vs lu for sizeof

I understand that %zd is the suggested way to format the sizeof result. However, I don't understand why that is necessary. For example using lu gives me the same output, and isn't the result of sizeof an unsigned long anyways? For…
carl.hiass
  • 1,526
  • 1
  • 6
  • 26
1
vote
1 answer

Taking character into array and printing it in C

I was interested in the following problem: Take the colors as characters (for example : 'y' for yellow, 'r' for red etc.) into an array and display the same. While displaying there should be a single space between each characters. So to do this I…
Infinity_hunter
  • 157
  • 1
  • 7
1
vote
1 answer

C language printf add additional useless message

I tried to simulate the linux file permission use st_mode, but when I print the result, it has an additional unwanted message. /* file permission */ char buf[9] = {0}; char tmp_buf[] = "rwxrwxrwx"; int i; for(i = 0; i < 9; i++) { if…
1
vote
1 answer

Why don't use msg in printing instead of msg[pointer -1]?

It is printing correctly but I have confusion that whenever I write just msg, it gives me Your ?@ and whenever I write msg[option-1], it gives me full message of Your name is bilal. I am not understanding the cause of [option-1]. Why it is used and…
Bilal Khan
  • 119
  • 1
  • 9
1
vote
2 answers

why use of %n in printf() is not printing the number of variable occurrence before %n In C?

#include int main () { int c; printf ("the value of %nc : ", &c); return 0; } Output : the value of 0