User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
DaniWeb is a massive community of 426,107 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,686 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Showing results 1 to 40 of 236
Search took 0.02 seconds.
Posts Made By: dwks
Forum: C 34 Days Ago
Replies: 1
Views: 187
Posted By dwks
Re: Help in Postfix to Binary Tree Representation

Why is root a global variable? As far as I can see, it doesn't need to be, and it's just causing confusion because several functions take a root parameter.
Forum: C Sep 4th, 2008
Replies: 11
Views: 387
Posted By dwks
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
Posted By dwks
Re: Problem with string to function argument

while ( !feof(ep) )
{
fgets(registryHive, MAX_PATH, ep);

Note that this is not a good idea...
Forum: C Aug 13th, 2008
Replies: 14
Views: 616
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
Re: C commands not working as they should.

You don't want a semicolon after a while loop:
while( number<= 0 ); {
->
while( number<= 0 ) {
Forum: C++ Aug 5th, 2008
Replies: 9
Views: 768
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
Re: c++ game help

switch (choice)
{
case '1':
saveGame();
case '2':
switch (missionNumber)
{
case 1:
...
Forum: C Jul 22nd, 2008
Replies: 9
Views: 544
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
Re: Printing a certain number of lines from a file.

while( line % 55 != 0 )
Note that 0 % 55 is 0, so you'll pause before printing anything, and then display 55 lines ad infinitum. The best solution is probably to use something like this:
while( line...
Forum: C Jul 16th, 2008
Replies: 10
Views: 458
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
Re: Help me play-test my text adventure? (beginner)

It looks very nice. I guess I only have one comment at the moment, and that is that printing multiple lines of text is easier if you use triple quotes instead of lots of different print statements....
Forum: C++ Jul 2nd, 2008
Replies: 4
Views: 242
Posted By dwks
Re: How to make a choise for the user to choose a file to open?

In order to use the ifstream fin variable that you declare inside the switch statement, you need to declare it outside the switch statement. For example:
ifstream fin;
switch(choose) {
case 1:
...
Forum: C++ Jul 2nd, 2008
Replies: 27
Views: 948
Posted By dwks
Re: Plzz help me out!!!!

http://board.theprogrammingsite.com/viewtopic.php?t=113&sid=57532b7c18db0b6089757cc195c714b4
Forum: C Jul 2nd, 2008
Replies: 15
Views: 1,215
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
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
Posted By dwks
Re: Unable to delete compiled programs?

Don't forget Dev-C++: http://bloodshed/net/devcpp.html

But I doubt that's the problem, if Ancient Dragon encountered the same issue.
Forum: C Feb 6th, 2008
Replies: 4
Views: 315
Posted By dwks
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
Posted By dwks
Re: Question about my project

switch ( Key ) {
case 'R':
case 'r':
Key_r();
break;
case 's':
case 'S':
Key_s();
break;
case 27:
Forum: C Oct 20th, 2007
Replies: 13
Views: 2,582
Posted By dwks
Re: Program calculate letter occurence in a sentence

Something like this. I've glossed over details that you seem to already understand.

Declare an array to hold the letter counts one element for each letter, with each element initialized to zero.
...
Forum: C Oct 20th, 2007
Replies: 8
Views: 2,476
Posted By dwks
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
Posted By dwks
Re: Reading from a file and counting how many time each letter occurs.

gotoxy() is an ancient Borland function. It's very unportable. No new code should use it or anything from <conio.h>, such as getch() or clrscr().


'a' is a single character. "a" is a string. Use...
Showing results 1 to 40 of 236

 
All times are GMT -4. The time now is 4:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC