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 5 years ago.
Improve this question
#include<stdio.h>
#include<conio.h>
void main()
{
printf("%d","");//printing output
getch();
}
The output is 173 .I am not getting why the output is 173.
First, you're trying to print a string as decimal integer, which means the decimal you try to print is going to be the pointer to the string (actually a pointer to the array of characters) and not the string itself. To use an individual character use single-quotes, not double-quotes.
To accomplish what you're actually trying to do, do this:
printf("%d", ' ');
Note there is an actual space between the two single-quotes.
The result will be 32, which is the decimal value for the ASCII Space character.
Related
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 4 months ago.
Improve this question
I am learning C right now and I understand that I can't add an integer with a decimal like so:
#include <stdio.h>
int main() {
printf("%d",15+9.0);
return 0;
However when running this I expected some sort of an error. Instead, I got a weird output:
-1866308488
Can someone help me understand why it gave me this output?
As #PaulMcKenzie said, C expected an int based on the %d format specifier. You gave it a double instead. C often gives unexpected behavior instead of throwing an error like Java or C#. What happens to a double variable when %d is used in a printf? says that the resulting behavior is undefined and OS-specific.
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 6 months ago.
Improve this question
my code is not identifying type string. I am using c to program
In your calls to count_letter(), count_words() and count_scenteces() you include a unnecessary string type in the function argument.
You should only include string when declaring a variable of some sort for example:
string x = "hi";
So to fix this problem replace each instance of string text in your function calls with text.
This will reference the text variable instead of inappropriately introducing a new variable of type string into the program.
Parameter types are only put in function declarations, not function calls.
int letters = count_letters(string text);
should be
int letters = count_letters(text);
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 years ago.
Improve this question
I'm learning C and trying to understand the printf function better.
When I print:
printf("%d", 6 << 1);
it returns 120x0 instead of the expected 12. Why is that? I'm using gcc compiler.
Change this
printf("%d", 6 << 1);
to
printf("%d\n", 6 << 1);
and try to always add a newline character to distinguish the printed text from other output, unless you need to print things next to each other.
You should now see
12
0x00
most likely you're code is working properly printing 12 and later you print 0x0 somewhere.
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 years ago.
Improve this question
I'm passing in an int to a function in my lame program. It's passing in a number to convert it to a binary representation as an int array.
typedef int bool;
bool* conv2bin(int num)
{
blah blah blah return binary as bool array
}
I pass in 78 and if I printf() immediately after it's passed in, I get 781237412753-124?
I'm new to C (coming from C++) so please tell me if I'm doing something really dumb?
This seems like it should be really easy but it isn't...?
EDIT:
Have I done goofed:
printf("%d", num);
EDIT 2:
It has to be something with the int because at the end of the function, it checks to see if we subtracted numbers sufficiently to get to num==0 but it says we're not at 0. It's doing really weird things. It also says that the binary is 0000000001001111, and it should be 0000000001001110.
Edit 3:
Wow I suck. Thank you Floris! It's been a long day.
Guessing hereā¦
Your printout starts with the correct two digits: 78.
But if you do not include a \n at the end of your formatting string, then the next thing you print will be concatenated. As will the next thing, and the next.
I suspect your problem will disappear when you change your print statement to
printf("%d\n", num);
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 years ago.
Improve this question
I have a variable:
int a = 0x0304;
I print it out like this:
printf("the value is 0x4x\n", a);
but it shows the value is 0x304, I want the result should be the value is 0x0304, how to print it out like this?
Try adding a leading 0 to your format specifier - %04x
printf("the value is 0x%04x\n", a);
Just in case its omission from your question wasn't a typo, note that I've also added a % to make this a format specifier. As it stands, the code in your question would have just echoed the value is 0x4x