Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I got some warning in my code. Is there someone who can help me?
I tried to change %d to %f but the program will then not work as I want to, like with the warnings.
In the line
printf("%d |%.2f \n", MOVE_FORWARD * i, i, MOVE_FORWARD);
You are doing three things wrong:
i) You used more arguments than format specifiers, you have 2 format specifiers and used 3 arguments namely (MOVE_FORWARD *i), (i) and MOVE_FORWARD
, you used printf to print only 2.
ii) You used wrong specifiers, MOVE_FORWARD * i is of type double, not integer.
iii) i is of type integer not double.
The correct way should be:
printf("%f |%d \n", MOVE_FORWARD * i, i);
if you want to print those two.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am trying to print a double and have been using %lf throughout my code, but when i compile the program two of the printf doubles come up with a warning saying:
format specifies type 'long double' but the argument has type
'double *' [-Wformat]
what format should i use to print this?
You should pass the double rather than a pointer to it.
You apparently have something similar to
double d = ...;
double *p = &d;
printf("%lf\n", p);
Replace the last line with
printf("%f\n", *p);
Also note the removed l, which is for use with integer conversion specificers.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
This is input: Francetic, Petra#13/12/1930 Trg zrtava Uskoka 156 (Skopje) 800893452/2008
It wont fscanf properly it show's m=0 and that's how I know that while loop was not successful.
while(fscanf(mrtvaciTxt, "%[^,],%[^#]#%d/%d/%d %[^0-9]%d (%[^)]) %[^/]/%[^\n] ",
&pomrli[m].prezime, &pomrli[m].ime,
&pomrli[m].dan,&pomrli[m].mjesec,&pomrli[m].godina, &pomrli[m].adresa,&pomrli[m].brUlice,
&pomrli[m].brOsobne, &pomrli[m].godSmrti )== 9)
{
m++;
}
printf("%d\n\n", m);
How can I fscanf this and is there any tutorial how can i be better at this because it takes me so much time.
Francetic
Petra
13
12
1930
Trg zrtava Uskoka 156 (Skopje)
800893452
2008, I want fscanf to look like this
There are multiple errors in the scanf format.
Here is the correct scanf format string:
" %[^,], %[^#]#%d/%d/%d %[^(](%[^)]) %[^/]/%d"
Here is the list of errors:
there are 11 % while you expect only 9 fields
lacking a space in front of the format string to consume the newline
there is a / in front of the first %d which shouldn’t be there
you are using a [^\n] where you should use [^(]( for the adresa
you are using %*[\n] for unknown reason
you should use [^)] to get the grad
etc.
you modified you question, so I don’t know what else you did.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
MyCode
#include<stdio.h>
int main(){
printf("result1 : %lf %d\n", (1 - (double)((int)1)), (1 - (double)((int)1)));
return 1;
}
Result
result1 : 0.000000, 1
I dont't understand this result.
I think when printf("%d"), this result must be zero!
Refer to the printf reference to find that the "%d" format specifier expects an int as parameter. Yet, you pass it a double. This is undefined behavior, meaning anything can happen, including the result you get (for more details on what's likely happening, refer to eg. What happens to a float variable when %d is used in a printf?).
Instead, try adding a cast to int :
printf("result1 : %lf %d\n", (1 - (double)((int)1)), (int) (1 - (double)((int)1)));
The type of the arguments passed to printf have nothing inherently to do with the format string. It is your responsibility to make sure the types match up. In this case, you are passing two double values. However, the format string is attempting to interpret the second one as an integer. This is undefined behavior.
While the behavior is undefined in the general case, it is likely that you are seeing the sign bit of the IEEE 754 double in a little-endian interpretation of an integer.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
is it possible to use same integers in multiple scanf's? For example, I input int i and j, then give them a value in scanf, and print their sum. Then use another scanf to assign different values to the same integers, and now add THEIR sum..
Do you mean this?
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
Of course it would work. The variable's value simply changes. Its the same if you wrote
int a;
a = 4;
. . .
a = 8
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
My C code is :
void main()
{
int a=5,b=6,c=11;
clrscr();
printf("%d %d %d");
getch();
}
When i compiled it , it is giving Compile time error but the answer to this question is : 11 6 5
I'm unable to understand how the output is 11 6 5
Please somebody tell the correct output with proper explanation .
Thanks
its behavior is undefined. if you want to show the values of a, b and c you should have coded as below:
printf("%d%d%d",a,b,c);
now the output is:
5 6 11
The program has undefined behaviour, since the printf format string requires that you pass three additional int arguments, which you aren't doing. Anything could happen. Printing certain output is one form of "anything".
Program's behavior is undefined. You well get anything.
You are passing no arguments to the printf function while it is expecting three int type arguments. The statement
printf("%d %d %d",c, b, a);
will give you desired output.
11 6 5