Forum: C 34 Days Ago |
| Replies: 1 Views: 187 |
Forum: C Sep 4th, 2008 |
| Replies: 11 Views: 387 Re: approximate the value of PI Declaring variables inside for loop initialization sections is indeed C99-only. I wouldn't do it if I were you.
double just has more precision (usually). Oftentimes, a float is 4 bytes and a double... |
Forum: C++ Aug 15th, 2008 |
| Replies: 3 Views: 237 |
Forum: C Aug 13th, 2008 |
| Replies: 14 Views: 616 Re: memory leak You can even use fancy preprocessor macros and so on to replace the malloc()/free() calls in existing code with your own functions.
BTW, __LINE__, __FILE__, __DATE__, and __TIME__ are all standard... |
Forum: C Aug 13th, 2008 |
| Replies: 4 Views: 435 Re: solving derivative of a function Why don't you use the quadratic formula (http://en.wikipedia.org/wiki/Quadratic_equation#Quadratic_formula)? If all of the equations are quadratic, it should work.
You can do square roots in C with... |
Forum: C Aug 13th, 2008 |
| Replies: 4 Views: 291 Re: fibonacci /* replaced 0 by 1 */
Depending on who you ask, the first fibonacci number can be 0 or 1. (Personally, I'd agree with you and have it 1.)
Why not use more descriptive names than num1, num2, etc? |
Forum: C Aug 13th, 2008 |
| Replies: 4 Views: 291 Re: fibonacci if(fib = fnum)
Try ==. = is for assignment, == is for comparison. (Your compiler should warn you about this if you enable warnings.)
Plus I don't think this is what you want.
for (fib=1; fib=num2 +... |
Forum: C Aug 5th, 2008 |
| Replies: 10 Views: 471 |
Forum: C++ Aug 5th, 2008 |
| Replies: 9 Views: 768 Re: How to create a byte array/structure The best way to do this is perhaps this: declare a structure representing the information. (Perhaps a header structure, a data one, a tail, and a packet structure that contains all three.)
If you... |
Forum: C++ Aug 5th, 2008 |
| Replies: 18 Views: 530 Re: enum warnings What? Never heard of that. Don't tell me,
this don't work
x = bool (x||y) ;
That is C++ only. The C way looks like this.
x = (bool)(x || y);
Perhaps the OP is compiling as C instead of C++.
As for... |
Forum: Perl Jul 24th, 2008 |
| Replies: 5 Views: 674 Re: problem Correction: it's difficult in C and C++, but of course Perl would have a module for it. ;) It looks like a very useful one, too . . . . |
Forum: C++ Jul 24th, 2008 |
| Replies: 10 Views: 426 Re: c++ game help switch (choice)
{
case '1':
saveGame();
case '2':
switch (missionNumber)
{
case 1:
... |
Forum: C Jul 22nd, 2008 |
| Replies: 9 Views: 544 Re: Optimizing OpenGL (SwapBuffer being slow) My only suggestion is to try a profiler so that you can see exactly where your program is spending all of its time. If you have access to the code from the other program, profiling it as well might... |
Forum: C Jul 22nd, 2008 |
| Replies: 3 Views: 292 Re: answer if u can What are you forgetting here?
for(j=0;j<41;j++)
for(i=0;i<79;)
txt[j][i]=32;
Hint: it's an infinite loop . . . .
And it's a lot easier to use character constants like ' ' and '\r' in your code... |
Forum: C Jul 22nd, 2008 |
| Replies: 2 Views: 266 Re: two letters = one number? You could save the numbers as you find them instead of printing them, say in a char array, and then print that array in reverse. On the other hand, it would probably be better to use a different... |
Forum: C Jul 22nd, 2008 |
| Replies: 10 Views: 458 Re: Help Me With Sorting Algo @Adak: I already mentioned that, though admittedly it was buried in my long post.
The main logical problem with your code still exists. Numbers aren't the same thing as strings. You can't have an... |
Forum: Perl Jul 16th, 2008 |
| Replies: 5 Views: 674 Re: problem You can read from and write to the same file at once, but it's difficult.
You're best off creating a copy of the file and modifying that, then replacing the original file with the modified one, as... |
Forum: C Jul 16th, 2008 |
| Replies: 7 Views: 387 Re: Can you use an array of pointers for fgets? for loops generally have three sections. You've forgotten the increment section. :)
You're also missing a closing parentheses on the strlen() call . . . .
But we know what you mean. :)
char... |
Forum: C++ Jul 16th, 2008 |
| Replies: 8 Views: 376 Re: Alignement So your question is, why does structure alignment apply to the last member of a structure?
I think the answer is the same as for why structure alignment exists in the first place. Structure... |
Forum: C Jul 16th, 2008 |
| Replies: 8 Views: 367 Re: problems with string struct members Yeah, most of the time it's a good idea. Sorry I didn't explain it further.
Yes. Accessing such memory could lead to data corruption or at the very least segmentation faults.
Correct.
Why?... |
Forum: C++ Jul 16th, 2008 |
| Replies: 10 Views: 426 Re: c++ game help Use code=c++ in your code tags to get syntax highlighting. It makes the code a lot easier to read.
iostream.h doesn't actually exist (according to the C++ standard). Consider using
#include... |
Forum: C Jul 16th, 2008 |
| Replies: 3 Views: 315 |
Forum: C Jul 16th, 2008 |
| Replies: 10 Views: 458 Re: Help Me With Sorting Algo That last post was getting crowded so I thought I'd start another one -- especially since it's a higher-level one.
Since you're trying to handle both numbers and strings, why not have two separate... |
Forum: C Jul 16th, 2008 |
| Replies: 10 Views: 458 Re: Help Me With Sorting Algo GCC doesn't like your code.
sort.c: In function ‘read_list’:
sort.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int *’
sort.c: In function... |
Forum: C Jul 16th, 2008 |
| Replies: 5 Views: 982 Re: How to read .bmp, .jpeg image in C language? You can read image files in your program in a standard way, if you want to write the reader yourself. wotsit.org is a good reference for this, as already mentioned.
Or you can use a library to read... |
Forum: C Jul 16th, 2008 |
| Replies: 8 Views: 367 Re: problems with string struct members ex_1.emotion_options = (char **)malloc(sizeof(char *[MAX_EMOTION_SIZE]));
That's uninitialized, so if you don't fill in MAX_EMOTION_SIZE elements of that array, then this will be freeing random... |
Forum: C Jul 4th, 2008 |
| Replies: 3 Views: 259 Re: Question about including C files Well, if you think it makes the program easier to understand, then what can I say? :)
I really do think that there must be a better way, but unless you post some real code I probably won't think of... |
Forum: Python Jul 2nd, 2008 |
| Replies: 3 Views: 332 |
Forum: C++ Jul 2nd, 2008 |
| Replies: 4 Views: 242 |
Forum: C++ Jul 2nd, 2008 |
| Replies: 27 Views: 948 |
Forum: C Jul 2nd, 2008 |
| Replies: 15 Views: 1,215 Re: Problem using atoi for my argv argument puts("Give me input numbers, each separated by space."); //gcc error: puts was not declared within this scope
You need to #include <stdio.h>, because that's where puts() is located.
The current... |
Forum: C Jul 2nd, 2008 |
| Replies: 24 Views: 1,193 Re: Convert struct to short Sorry to go behind jephthah's back here, but if this is your original structure
typedef struct ip_header{
unsigned char headlen:4; // header len
unsigned char ver:4; // version
unsigned char ... |
Forum: C Jul 2nd, 2008 |
| Replies: 8 Views: 908 Re: c program to remove blank spaces So does Perl! In fact, you can do it with just one line, on the command line.
perl -pe 's/\s/g'
But that's beside the point.
Note that ssharish's code works, but it might be more efficient to shift... |
Forum: C Jul 2nd, 2008 |
| Replies: 3 Views: 259 Re: Question about including C files It seems to me that .h files would be better for this, if all you're doing is managing constants (and not actual executable code).
The standard place to include header files, of course, is at the... |
Forum: C Jul 2nd, 2008 |
| Replies: 8 Views: 356 |
Forum: C Feb 6th, 2008 |
| Replies: 4 Views: 315 Re: Division /subtraction of two structures. Well, if
then you're out of luck, because, as you say, those numbers could not fit into a 32-bit integer.
On the other hand, if you want one of your structures as the result . . .
If the bases are... |
Forum: C Oct 20th, 2007 |
| Replies: 6 Views: 482 |
Forum: C Oct 20th, 2007 |
| Replies: 13 Views: 2,582 |
Forum: C Oct 20th, 2007 |
| Replies: 8 Views: 2,476 Re: number of times each number in array occurs? Use code tags when you post code -- otherwise it will be an unreadable mess.
This is also the C programming forum, not the C++ one, so C++ code is out of place.
It's also old-style C++ code. You're... |
Forum: C Oct 20th, 2007 |
| Replies: 6 Views: 1,076 |