Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,287 I can, but I won't. As horrifying as the concept clearly is, you need to apply some effort to understand the answers you've been given. |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,287 You need to put some effort into understanding the answers you receive, rather than giving up if you're not given code examples.
The approach with using pointers is;
SomeTypeA Function(... |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,287 A common way of return multiple values is by returning a struct which has multiple members, or for the function to accept a pointer that receives additional data from the function.
You don't... |
Forum: C Jan 9th, 2009 |
| Replies: 7 Views: 974 Maybe so, but that doesn't make it a good idea.
If your function assigns *outputbuffer to something to something that is not a char *, and then main() dereferences it, the result is undefined... |
Forum: C Jan 2nd, 2009 |
| Replies: 3 Views: 925 What can I say? I was tired. My sig also applies. |
Forum: C Jan 2nd, 2009 |
| Replies: 3 Views: 925 The first line puts a space into the first char of a, and a zero into the second char. All other elements of a are uninitialised. Hence the compiler diagnostic (which will usually be a warning,... |
Forum: C Dec 29th, 2008 |
| Replies: 3 Views: 423 If by ``"c" programme'' you mean something that is compliant with one or both of the C standards, then there's only one answer: it's impossible. Your not wanting such an answer does not make it... |
Forum: C Dec 27th, 2008 |
| Replies: 1 Views: 493 Look up the standard C functions in the C standard library, through <stdlib.h> or (in C++, through the <cstdlib> header). srand(int) is used to initially seed the generator. rand(), when... |
Forum: C Dec 9th, 2008 |
| Replies: 7 Views: 2,017 Your first problem description had almost no relationship to your second.
The %x format specifier (for scanf() and related functions) reads a hex value (with the 0x prefix) and stores it in an... |
Forum: C Nov 29th, 2008 |
| Replies: 1 Views: 300 Tip: If a and b are integral values then a % b gives the remainder that is left over when dividing a by b. |
Forum: C Nov 6th, 2008 |
| Replies: 3 Views: 337 Don't use %d to print out pointers.
Other than that, try explaining what you expect the code to do, and then compare that with what the code does. |
Forum: C Oct 28th, 2008 |
| Replies: 22 Views: 1,856 Pfft! People earn what they get from me: good or otherwise. |
Forum: C Oct 28th, 2008 |
| Replies: 22 Views: 1,856 Wash your mouth out with soap. main() returns int. |
Forum: C Oct 28th, 2008 |
| Replies: 22 Views: 1,856 I'll answer your question with a question.
Under what conditions will
if ((x < 1 || x > 4) && printf("Goofy"))
{
printf(" is also known as Dippy Dawg");
}
print out "Goofy is also... |
Forum: C Oct 27th, 2008 |
| Replies: 22 Views: 1,856 A post-test loop is a generic name for a loop of the form do { ... } while (condition), as opposed to a while(condition) {} loop.
The solution, if you have to do that, is to have the printf()... |
Forum: C Oct 27th, 2008 |
| Replies: 6 Views: 819 (1) strtok() assumes both its arguments are strings that are terminated with a 0 character. Behaviour is undefined if that is not true.
2) strtok also returns NULL if it cannot find a token... |
Forum: C Oct 24th, 2008 |
| Replies: 8 Views: 2,125 It is equally rude to provide misinformation, and describing a trivial concern as a timebomb is misinformation - and, worse, misinformation that can deceive beginners. I certainly agree it is... |
Forum: C Oct 24th, 2008 |
| Replies: 1 Views: 826 It's usually called a compiler!
Quite a few mainstream compilers have an option to emit assembler code (for the target system) rather than compiled object files. You need to read the... |
Forum: C Oct 24th, 2008 |
| Replies: 8 Views: 2,125 Oh, rubbish! Your description is excessive. The worst thing that can happen is that another function needs to call the declared function, and a compiler error occurs unless the function declaration... |
Forum: C Oct 18th, 2008 |
| Replies: 24 Views: 8,792 Not even close.
Your code does not insert any characters into the string array. What is the purpose of the "input" argument supplied to the function? where is the codes counting the number of... |
Forum: C Oct 18th, 2008 |
| Replies: 16 Views: 2,596 You're wrong. getchar() does not behave in quite the way you described. Consider yourself corrected.
Salem is right. Once you get past the concern he pointed out, there are also additional... |
Forum: C Oct 18th, 2008 |
| Replies: 6 Views: 792 scanf() would return an EOF in that case.[/QUOTE]
No it will not. It will return zero in that case.
EOF is only returned upon reaching end of input. If there is input in the stream that does... |
Forum: C Oct 17th, 2008 |
| Replies: 11 Views: 1,894 Yeah, right. That's like suggesting flying in a 747 with a small leak in the fuel tank .... it may seem OK at first, but the results you get in the future are better avoided in the first place.
... |
Forum: C Oct 16th, 2008 |
| Replies: 6 Views: 1,274 As you say, Narue, my answer was what "kinda sorta" sometimes happens.
My shorter answer is the one I like for this type of question: completely accurate. But it, almost invariably, is not... |
Forum: C Oct 15th, 2008 |
| Replies: 6 Views: 1,274 The short answer: wherever the compiler and/or system choose to store them.
A longer answer follows.
Older systems used to make a distinction between "stack" and "heap" (e.g older IBM... |
Forum: C Oct 14th, 2008 |
| Replies: 6 Views: 1,771 Wrong. As Dave said, comparison of char arrays (aka "C style strings") should usually use strcmp() rather than ==. |
Forum: C Oct 14th, 2008 |
| Replies: 1 Views: 516 The simpler way (less error prone) is to use a typedef helper.
typedef float ((*YourFunction)(int, int);
YourFunction YourArray[3];
or, if you wish code that is terse but easier to get... |
Forum: C Oct 14th, 2008 |
| Replies: 10 Views: 873 Yes. Look up the C standard header stdarg.h or (in C++) the standard header <cstdarg>. Those headers contain macros and types that support writing functions with variable argument lists. |
Forum: C Oct 12th, 2008 |
| Replies: 4 Views: 964 Apart from that, it often takes a lot more effort to write assembly code to achieve X than it does to do X in a higher level language like C. C also has a library .... which means it is not... |
Forum: C Oct 7th, 2008 |
| Replies: 3 Views: 2,082 x is not initialised to point at anything and you are dereferencing *(x+i*nc+j) in your loops.
Before your loops, you need to make x point at something valid, such as the first element of an array... |
Forum: C Oct 5th, 2008 |
| Replies: 3 Views: 451 Yeah, I noticed that too. I assumed the post was just typing what she remembered having, as the code could never compile, so just focused on "uninitialised variables yield crap results, even if code... |
Forum: C Oct 4th, 2008 |
| Replies: 6 Views: 985 There is also the incidental concern that your function is recursive, which does not meet the requirement to be non-recursive. |
Forum: C Oct 4th, 2008 |
| Replies: 3 Views: 451 You have not initialised min, ret, cent, or invalid, which means their starting values are undefined (ie can contain random junk). Then, in your loop, you increment them. You then add the... |
Forum: C Oct 4th, 2008 |
| Replies: 8 Views: 2,161 A c-style string (eg a string literal) is an array of char that, by convention, is terminated with '\0'. |
Forum: C Oct 3rd, 2008 |
| Replies: 8 Views: 2,161 Because the %s format specifier tells printf() and related function that the corresponding argument is a pointer to char and to keep printing chars until it finds a zero.
When an array is passed... |
Forum: C Oct 1st, 2008 |
| Replies: 8 Views: 2,161 That's not true. You have explicitly initialised two elements of three-element array. The standards go about it in a round-about way (there's a logic train to follow to get to the conclusion, and... |
Forum: C Sep 27th, 2008 |
| Replies: 4 Views: 571 You need to make DB, etc pointers to char.
sizeof(char) is 1, by definition in the standard. So if DB is your base address, DB + 1024 is a pointer to a location 1024 bytes after DB. |
Forum: C Sep 16th, 2008 |
| Replies: 2 Views: 539 The standards specify that elements of declared arrays are contiguous. N-dimensional arrays are actually arrays of (N-1)-dimensional arrays. So ..... the compiler is required to do what you want (at... |
Forum: C Sep 13th, 2008 |
| Replies: 4 Views: 1,488 1) First, represent a polynomial (of the form c_0 + c_1*x + c_2*x^2 + .... c_n*x^n) is represented by an array with elements (c_0, c_1, c_2, c_3, .... c_n).
2) Work out how to multiply two... |
Forum: C Sep 11th, 2008 |
| Replies: 4 Views: 474 Firstly, your variables a, b, and c are uninitialised: their value before entering the loop could be anything.
As to your loop, it doesn't really make sense.
You only need two variables. An... |