Forum: C May 12th, 2007 |
| Replies: 2 Views: 1,734 Ok, first, if you'd read the rules and guidelines, you'd have seen that you should post your code between and tags. That preserves the indentation and adds line numbers to make it easer for us to... |
Forum: C May 3rd, 2007 |
| Replies: 3 Views: 3,172 As I recall, the ASCII for a space is 32, not 0127 (which is a 'W'). I recommend you look at the isspace(int) function available from <ctype.h> as it will match all whitespace characters (spaces,... |
Forum: C May 3rd, 2007 |
| Replies: 13 Views: 1,710 Optimization techniques: link (http://en.wikipedia.org/wiki/Performance_analysis) link (http://en.wikipedia.org/wiki/Optimization_%28computer_science%29) For the second one, pay attention to the... |
Forum: C May 1st, 2007 |
| Replies: 13 Views: 1,710 There isn't exactly a whole lot there to bother optimizing. And be sure that the code you're working on is worth optimizing. Most of the time people try to optimize their code, they end up worrying... |
Forum: C Apr 19th, 2007 |
| Replies: 2 Views: 1,052 http://en.wikipedia.org/wiki/Sorting_algorithms |
Forum: C Apr 17th, 2007 |
| Replies: 4 Views: 1,550 Or, you could just pass it as a pointer. And either way, you'll want to pass some sizes with it to make sure you stay within your allocated memory. |
Forum: C Apr 16th, 2007 |
| Replies: 8 Views: 9,453 I just get warnings rather than errors, but the problem is pretty simple. You're missing a declaration of funct. In C you need to declare (if not define) a function before calling it.
... |
Forum: C Apr 16th, 2007 |
| Replies: 8 Views: 9,453 could you post the code please? And be sure to use and tags :) |
Forum: C Apr 16th, 2007 |
| Replies: 8 Views: 9,453 You just pass argv[2] to the function:
void function(char* fileToOpen);
int main(int argc, char** argv) {
FILE* fp1 = fopen(argv[1], "w");
function(argv[2]);
}
void function(char*... |
Forum: C Apr 15th, 2007 |
| Replies: 5 Views: 1,649 with some code or description of what you've attempted |
Forum: C Apr 14th, 2007 |
| Replies: 2 Views: 1,019 You'd have multiple definitions of main, which is an error.
A few other points:
- main's return type should be int.
- you should never include .c files. The compiler will create object files... |
Forum: C Apr 13th, 2007 |
| Replies: 4 Views: 1,813 When you use a variable twice in an expression and one of those instances is a pre- or post- increment, the behavior is undefined (and then depends on how it's implemented by your compiler). |
Forum: C Apr 11th, 2007 |
| Replies: 2 Views: 1,382 I think you could use freopen to do it somehow... I'm not sure that it'll work, but hopefully it'll at least be a starting point. |
Forum: C Apr 9th, 2007 |
| Replies: 6 Views: 2,226 No, I'm pretty sure his demands are legit. There are times in a low-level application where you need to specify a certain address (MMIO is an example of this, albeit a poor one). He'll be just fine... |
Forum: C Apr 9th, 2007 |
| Replies: 6 Views: 2,226 This isn't tested, but it should give you the idea:
int* a = 0x8000;
int* b = 0x8000 + sizeof(int); // account for a
int* c = 0x8000 + 2*sizeof(int); // account for a and b
double* test =... |
Forum: C Apr 9th, 2007 |
| Replies: 6 Views: 2,226 If you know where you want the data, just create a global variable pointing to it. This of course assumes that you point it to a valid address, and you'll have to make sure they line up (and don't... |
Forum: C Apr 7th, 2007 |
| Replies: 10 Views: 5,826 Actually, according to this very enlightening read (http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx), you're all wrong...
(sorry, I couldn't help it either) :mrgreen: |
Forum: C Apr 3rd, 2007 |
| Replies: 2 Views: 719 When you get an error with your code, please post that next time. Anyways, the error I got was that on line 19 you declare a Bev_Iterator* without having declared the class first. Put this line... |
Forum: C Apr 1st, 2007 |
| Replies: 29 Views: 3,356 What you have to do is for each item in words, you need to see if the pattern can be found in puzzle. It's not just a matter of checking if words and puzzle are equal. You need to see if the... |
Forum: C Apr 1st, 2007 |
| Replies: 29 Views: 3,356 We have char* puzzle[]. Think about how pointers and arrays are related (hint: you can index a pointer like you can an array). So we can treat puzzle as though it were char puzzle[][].
For... |
Forum: C Apr 1st, 2007 |
| Replies: 10 Views: 8,796 I don't think you even need Top3 (and you're using it uninitialized, which is bad). Top will be updated as you call pop, so you could probably just do:
while(Top)
pop(Top); |
Forum: C Apr 1st, 2007 |
| Replies: 29 Views: 3,356 Here's how the 2-d indexing works: you've got Array[row][col]. col is the horizontal index, row is the vertical one. So if you want to check for a horizontal match you check from your starting... |
Forum: C Apr 1st, 2007 |
| Replies: 10 Views: 8,796 I tried running it and after a few small touchups (no logical changes though) it seems that you're off to a good start. Here's how it went:
$ ./a.out
this is a line
enil a si siht As you can... |
Forum: C Apr 1st, 2007 |
| Replies: 29 Views: 3,356 How would you do it by hand? There's a variety of methods, but here's one you could try to implement:
- search each row for the first letter of the word.
- if the word fits horizontally, see if... |
Forum: C Apr 1st, 2007 |
| Replies: 7 Views: 2,292 pass the pointer and the length of the array. |
Forum: C Mar 31st, 2007 |
| Replies: 10 Views: 1,302 You'll need a bignum library. I've seen mention of the Gnu Multiple Precision (http://gmplib.org/) library before, so you might give that a shot. |
Forum: C Mar 26th, 2007 |
| Replies: 4 Views: 2,234 Instead of giving a book answer, I figured I'd help you help yourself: did you try it? You can learn a lot just from experimenting and seeing if something works or not. |
Forum: C Mar 9th, 2007 |
| Replies: 3 Views: 1,092 You could also do something like this:
printf("%4d", (int)ceil(solution - 0.5));
This'll print the rounded value without actually changing the double, so your other numbers should be fine.
... |
Forum: C Mar 8th, 2007 |
| Replies: 21 Views: 5,714 Actually, my brain wasn't really functioning either, now that I look at it. The no-brainer algorithm we all jumped on works so long as the coins are multiples of each other, or have a fairly high... |
Forum: C Mar 8th, 2007 |
| Replies: 21 Views: 5,714 To summarize the algorithm provided by Lazarus, you just add as many of the biggest coin you can. Then repeat for the next biggest until you have the amount. |
Forum: C Mar 6th, 2007 |
| Replies: 4 Views: 1,975 Pretty much, you're trying to give a rough approximation of how much work you'll have to do with respect to the number of items you have. Generally, small overheads or statements that only execute... |
Forum: C Feb 28th, 2007 |
| Replies: 13 Views: 2,114 Are you saying that it's worse, or that easier isn't better? |
Forum: C Feb 24th, 2007 |
| Replies: 16 Views: 5,420 and is there a logical problem with your code...?
By the way, main should return a type int ;) |
Forum: C Feb 14th, 2007 |
| Replies: 12 Views: 31,409 A double pointer has two basic meanings. One is of a pointer to a pointer, where changing the value of double pointer will result in the original pointer being changed. Another is that of a... |
Forum: C Feb 3rd, 2007 |
| Replies: 5 Views: 4,534 Didn't really look at your code, nor do I intend to, but I'll propose a few methods for breaking out of nested loops:
- LIke WaltP suggested, use a variable as a break condition. Check it in your... |
Forum: C Feb 2nd, 2007 |
| Replies: 5 Views: 989 for the original problems, the answers should be 20 and 256. Since it's a loop, it'll repeat until the condition is false (i.e. until a>12 and a>25 respectively). |
Forum: C Jan 29th, 2007 |
| Replies: 1 Views: 756 You probably would be best to look into a threading library and make your program multi-threaded. |
Forum: C Jan 10th, 2007 |
| Replies: 11 Views: 2,333 You'll need to be consulting documentation for those. Most of the time, all of those functions will already be compiled into libraries, and your linker will reference the libraries when it puts your... |
Forum: C Jan 9th, 2007 |
| Replies: 14 Views: 2,515 I'm thinking your circular queue is more complicated than it should be. Here's how I would write one:
struct circular_queue
{
someFormOfData** data;
int head, tail, count, size;
};
... |
Forum: C Jan 9th, 2007 |
| Replies: 6 Views: 1,660 Just noticing a few things (using WaltP's code as a reference):
1) using sizeof(buffer) will not give you the right length since buffer is a pointer, so it'll probably be the same size as an int. ... |