Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
#include<stdio.h>
void main(){
if(printf("Hello World")){
}
}
this is editted which i copied from the compiler ...
Try this its truly working and print as Hello World
You have to remember that a function call is an expression, and that in C you can have any expression as the condition for an if statement.
Not sure what the problem is here.
printf() is just a function. It returns a value (an int that says how many characters were printed).
So when used as the controlling expression in an if, of course it's called ("evaluated") since the if needs to know the return value.
Calling printf() has the usual side-effect of generating output.
I've tried running this and got following Build messages
However, printf() returns the number of characters it has printed , Unless you put printf("") as condition, it will evaluate to be true. ;)
printf("Hello World") is an expression not statement, so you don't need semi-colon there.
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 9 days ago.
Improve this question
check (https://i.stack.imgur.com/AHR2c.png) in this picture you can see problem
this is c language question in this question i put any character or string type value at run time it has to be show error but it is showing even why?
Whenever we try declare a variable before initializing it, It stores an undefined value which is unpredictable and varies from run to run, compiler to compiler and it is always recommended to initialize your variable.
And scanf function is a type-unsafe function and it does not check the type of the value which you are entering and of the value which you enter is not a integer like you try to store a string value in the integer type variable then it will assign some undefined value which is also unpredictable and it is a indication of that the value you have entered in Invalid.
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 know it is not recommended to post code as an image, since I am getting a formatting error when trying to post code on here. Anyway, I am trying to write a simple C program to count number of words, characters, newlines using do while loop. However, the output is not as expected. Please help!
Instead of a do-while, you should try using while. Since your code starts off by checking whether a is any of your if cases, it goes to the else case, and increments the New line variable. If possible, could you share the output screen.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In C, I'd like to make a macro called TEST() that takes a valid C arithmetic expression and prints and evaluates it. So as an example, if I were to give it TEST(5*2+3) it would print to console 5*2+3 = 13. Unfortunately, I don't know how to convert an expression to a string nor do I know how to take a given string and evaluate it as code. How would I do this?
You can use the stringification operator to turn the argument into a string, then expand into a printf() call that prints the string and the result. My code assumes that the expression is always an int.
#define TEST(EXP) printf("%s = %d\n", #EXP, (EXP))
For the parsing part of your question:
The Shunting-yard algorithm is what you're after.
It is the most common way (that I know of) to convert a mathematical expression represented by a string of characters into a postfixed version(operators come after the operands instead of between), which is much easier to interpret with code.
Good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I just started getting a weird printf output, has anyone ever seen this? Any idea what it could be caused by?
http://imgur.com/4Mt6xdi
Edit
Here's the code. I'm new to c so if anything (even if it's not causing the error) looks wrong or uncommon please tell me.
printf(f2,"%8.31f\t%8.31f\n",x[0],x[2]);
fprintf(f2,"%8.31f\t%8.31f\n",x[1],x[2]);
In the code you write:
if (x[0]*oldx<0)
{
printf(f2,"%8.31f\t%8.31f\n",x[0],x[2]);
fprintf(f2,"%8.31f\t%8.31f\n",x[1],x[2]);
}
where f2 is a pointer to FILE, which shall not be passed as the first parameter of printf. Just remove it.
At least one problem is on lines 96-97:
printf(f2,"%8.31f\t%8.31f\n",x[0],x[2]);
fprintf(f2,"%8.31f\t%8.31f\n",x[1],x[2]);
The first line should call fprintf, not printf.
Any compiler should give you at least a warning for calling printf with a FILE* as the first argument. Did you see such a warning? If so, why did you ignore it?
Compiling with additional warnings enabled should show you a number of other problems. Fix those before doing anything else.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Basically I am a Java programmer, and not very well know about pointers in C.
so,
#include<stdio.h>
int main( ){
char*______Time______ = "world";
printf("%s",_____Time_____);
return 0;
}
I guess the output here should be: world ?
Is something spooky here which I should know?
Thanks for any help.
This should print "world", yes.
It looks a bit like it's trying to play with the GCC built-in preprocessor symbol __TIME__, but of course it's spelled wrong to do that.
I expect to see world, but your shell might then see that the last command ended without a newline and it might add something to signify that before starting its prompt on a fresh line.
and not very well know about pointers in C
A pointer is a variable which points to a specific address in the memory.
In this case, it points to the first letter of "world", which is then printed by printf() all until NUL (automatically inserted at the end of strings).
So, answering your question: yes, the output will be "world".