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've gotten to the end of chapter 5 of K&R C second edition, which is about pointers. I've done ok and understood everything so far, but for some reason I'm struggling to understand what exercise 5-18 is asking:
"Make dcl recover from input errors"
Sounds simple enough, but how far is the question expecting me to go? Just missing parentheses, lack of newlines, etc? I would appreciate knowing how others have solved this problem. Thanks.
You can see some specific examples about how this is solved:
example1.
example2.
example3.
There are few more examples if you look in Google.
Related
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 have experienced a strange problem when using assert in my program.
The program does not terminate even when I add a line of codeassert(false).
But the assert works when I write several lines of sample code. Anybody know why it happened?
If you have:
#define NDEBUG
this turns all assert's into nop's.
If you have differing behaviour, depending on the amount of code, then I guess you don't have NDEBUG defined and I would guess the compiler is simply compiling out the redundant code.
More details about environment are required, however, you give a definitive answer.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have tried to find it in google, but I couldn't.
I am studying C.
And now my stage is pointer and function about management memory.
But malloc, realloc, calloc...etc are hard to memorize.
So I want to know the full context. It will help to remember their meaning.
I do not speak English well. So my writing may be weird.
Please understand. Thanks for reading.
Memory Allocation (and reallocation etc...)
There is an awful lot to say about these functions but check out this article for a start.
And if you can still buy it read "The C Programming Language" by Brian Kernighan and Dennis Richie. A MUST Read
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 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
Can anyone tell me how to find (2^101100111000)%1000000007 in C?
There is a problem in which we have to convert a number into binary(1<=N<=600000) and find
2^(binary representation of N)modulo1000000007.
The values you are talking about will not fit into a standard long on any architecture, so you will have to use an arbitrary precision maths library such as GMP.
Hmm, just read Zong's answer... he's pointing to a more efficient method... haven't finished reading through the article but it looks like the better way to go...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
I'm a C beginner and I'm learning "heap" currently. One thing confuse me is can we store an array in heap? If we can, how?
Say for example:
int main(void) {
char sentence[] = "Please move me to heap.";// I want to store this sentence in heap
printf("%s\n", sentence);
}
Can somebody clarify this point to me? Thanks in advance.
Please have a look at this C tutorial and then have a look at malloc.
There is an example use of malloc here. If you are learning, it is better to read a slightly longer tutorial than for us to give you the answer in code as the former will better your understanding.