sprintf giving out the wrong numbers Arduino [closed] - c

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
trying to add the float to the link below.
float val1 = 51.48
sprintf(buffer, "/xxx/xxx.php?load=%d", val1);
when I print val1 it show as 51.48 but when i use sprintf and then print the buffer it show -6501 i dont understand what is going on.

use %f instead of %d in sprintf. %d is for printing integer so its truncating the digits after decimal point.
float val1 = 51.48
sprintf(buffer, "/xxx/xxx.php?load=%f", val1);

Related

C code doesnt show anything on the console [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I was trying to multiply a double and an int but it shows nothing.
My code is:
#include <stdio.h>
int main()
{
double vergi = 0.01;
int fiyat = 20;
double sonuc = fiyat * vergi;
printf("%s", sonuc);
}
The %s specifier is for a String. As per the doc says, you should use the %f specifier in printf for a double result.
Wrong conversion type in printf.
You want to print variable which type is double.
This is correct - printf("%lf\n", sonuc);

C prog that generates/output 3 numbers (any combination from 1 - 20) when added is equal to 20 [closed]

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
C prog that generates/output 3 numbers (any combination from 1 - 20) when added is equal to 20. Hope you could help me with this one. Thanks in advance.
int main(){
int num1,num2,num3,sum;
do{
printf("%i+%i+%i=%i\n",num1,num2,num3,sum);
} while(sum=20); getch();
}
Try this one. You should be able to modify it according to your needs.
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=20;i++)
for(j=1;j<=20;j++)
for(k=1;k<=20;k++)
if(i+j+k==20)
printf("%d %d %d\n",i,j,k);
return 0;
}

How Output of this program comes out to be this [closed]

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
Its C program which is running x86_64 machine ,Wanted to know how output is coming like this way
main()
{
int *mess;
mess=malloc(1);
mess[0]=1;
//mess[1]=2;
printf("%d",mess);
}
Now output here is 6295568
How is it??
You're printing the address where your int is stored. You need
printf("%d",*mess);
to print its value.
You are also allocating too little space for your int, you should do:
int *mess = malloc(sizeof(int));
instead of
int *mess = malloc(1);

I need to write a C program that adds two numbers each of 100+ digits? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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
Improve this question
Need to write a C program that adds two numbers each of 100+ digits..
I don't want the method of using arrays to do this.
Please suggest me how to store this numbers(atleast of 512 bit sized) and do the arithmetic operations?
You could use an arbitrary precision arithmetic library, such as GMP for that.
A quick C example:
#include <gmp.h>
mpz_t a, b;
const char *huge_decimal_num1 = "46819294521564960351683095841209562359068";
const char *huge_decimal_num2 = "6904120584864540916814056801234572451249681";
mpz_init_set_str (a, huge_decimal_num1, 10);
mpz_init_set_str (b, huge_decimal_num2, 10);
mpz_add (a, a, b); // a = a + b
printf("%s + %s = %s\n",
huge_decimal_num1, huge_decimal_num2, mpz_get_str (NULL, 10, a));

What are the origins of the name "scanf" and the specifier "%g"? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
What does the "f" in 'scanf' mean?
Also, why are double values signified by "%g" - what does the g mean?
My guess would be that the f means that the function takes a format specifier, as does printf().
%g = %f + 1, I guess, as %d was taken for "decimal integer".
Full list, with descriptions, can be found here.

Resources