Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why would you want to do that (unless one is a library or DLL)? If foo.h is in both projects then Code::Blocks should recompile both projects when foo.h is changed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How to create new threads is operating system dependent. MS-Wiondows does not support the POSIX. boost libraries try to be os independent.

Here are a lot of related threads

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's the strangest C code I've ever seen.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see any way to do that either in Code::Blocks. But it is quite easy with VC++ 2005/8/10. That has an option to add a new project to the existing solution, which is what you want to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code I posted needs to be called repeadedly until it returns a single digit value. But your solution is a lot better and less time consuming. But I don't know if it is something that a student would want to turn in as the solution to the problem because most likely the teacher would ask him to explain it, which he may or may not be able to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This program doesn't quite solve the problem
I didn't intend for it to be a complete solution. We are not supposed to provide complete solutions to home work problems.

I like your solution :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on the operating system. QT is cross platform.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The best way to learn c++ is to buy a book. There is an entire thread devoted to that topic here. That thread was started 6 years ago but its still relevant because the language has not changed much since then.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't hold your breath waiting for them :) All you have to do is read the other threads here and you will find millions of examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You might try one of these

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char str1="";

That's wrong, most likely just a typo and is correct in the link you posted.

>>Hope I am able to explain my problem..
What problem? I though you said your questions were answered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This may work..

Nope.

You really should compile and test the code you post that is supposed to solve, partially or otherwise, a problem.

Your code assumes all the bits are 1, which will usually not be the case.

And what's that temp variable? Its not declared anywhere in your code.

line 1 of the code you posted does not declare a functon.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>OP: put the above sample inside this (I've kept it as simple as possible)...

Please don't. main() always returns an int, its never void even though some compilers may let you get away with it.

int main()
{

}

>>was there an issue with the content?
Yes. It was not necessary to use sprintf(). strcpy() would have been sufficient.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you set the variable to 8 then it had better print 8. Afterall, that's what you told it to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume you mean the console screen.

First you have to figure out the screen width in characters. The old MS-DOS window was 80 characters wide, but that is no longer true. Once you know the screen width then the rest should be easy math. Something like this:

int main()
{
    std::string name = "Daniel";
    const int ScreenWidth = 80;
    while( name.length() > 0)
    {
        int center = (ScreenWidth-name.length())/2;
        cout << setw(center) << " " << name << '\n';
        name = name.substr(1);
    }
}
NicAx64 commented: MS dos is not the command shell anyway.`cmd.exe` is a command interpreter and it's completely 32-bit mode command shell ,in 64 bit environments the older protected mode environment was not exists anymore. and command.com is different from cmd.exe. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already told you -- read this VERY VERY SLOWLY: The default value of local variables is what was already contained in the memory location. If it has a value of 9 then that means that memory location contained a 9. Run the program again and it might display a different value.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

globals are initialized to 0. Locals are left uninitialized, so they just contain whatever random value was at that memory location when the variable is created. If you see a local that has the value of 0 then that means either you explicitly initialized it to 0 or the value of the memory location was already 0. Allocated memory return by either new or malloc() works the same way.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, you would be doing it wrong. There is no need to hard code the number of digits.

int sumdigits(int n)
{
  int sum = 0;
  while( n > 0)
  {
    sum += (n%10);
    n /= 10;
  }
  return sum;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>5+6+8+9+7+9+8+8 = 58
Wrong. you have 8 listed in both the last two digits. Should only be 5+6+8+9+7+9+8=52. 5+2=7.

At any event you need a loop that uses the mod operator % (e.g. num % 10) to extract the digit and divide operator / to remove it from the number in preparation for the next loop iteration.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>scanf("%s", & current_ptr -> name);

scanf() will not allow you to enter a name with spaces. If you want the spaces, such as first <space> last name then use fgets() fgets(current_ptr->name, sizeof(current_ptr->name), stdin); One problem wth fgets() is that it will add the '\n' enter key to the end of the input stream, which you need to strip out

if( current_ptr->name[strlen(current_ptr->name)-1] == '\n')
   current_ptr->name[strlen(current_ptr->name)-1] = '\0';

>>scanf("%f", & current_ptr -> hours);
That will leave the '\n' Enter key in the keyboard buffer s that the next scanf() with %s or fgets() will just grab the '\n' and not allow you to enter any text. What you need to do is flush that '\n' out of the keyboard buffer. One way to do that is by just calling getcar(). Here is a little program to illustrate the problem. Run it a couple of times first as it is written and then again by commenting out the getchar() on line 9.

int main()
{
    char buf[255];
    float f;
    printf("Enter name\n");
    fgets(buf,sizeof(buf),stdin);
    printf("Enter pay\n");
    scanf("%f", &f);
    getchar();
    printf("Enter more text\n");

    fgets(buf,sizeof(buf),stdin);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@blitter: If you want to post code like that at least make it a complete function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look at the file cstring and you will find out for yourself what the difference between it and string.h is. My compiler just includes string.h in cstring an them does the using statements for each of the functions

Honestly now -- how difficult is it for you to look at the file cstring and find out the answers to your question yourself???

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why? You have only one link -- next. How are you supposed to get from the current node to the previous node unless there is another link that points backwards in the list? To print your linked list backwards you have to start at the last node (tail) and work backwards towards the beginning.

Its a whole lot easier to just add the new nodes to the end of the existing list.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now that you posed all that, which parts do you not understand? (give us the line number(s))

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> with all Microsoft's functionality - and even more

Can it play movies that are on DVD?

How about games -- when you go to a store that sells PC games how many of them are for *nix?

What can Ubuntu do that MS-Windows can't (or doesn't) ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

define a structure

struct coord
{
   int x;
   int y;
   int z;
};
Software guy commented: Yep so right +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know. There was a way under MS-DOS 6.X. I thought M$ may have made it a Windows Hook, but I don't see anything that would be useful to you there.

You might read these links

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I know what's wrong -- I had the DaniWeb newsletter in mind. Did you stop publishing it?

As for News -- rarely read those articles.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I used to read it, but have not seen the link with this new design. I posted a complaint about that but I suppose it got lost in the shuffle. There used to be a link at the bottom of each page, near the About Us line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put a disk in the drive :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> submitted 400 jobs to cluster
What does that mean?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

strcpy() does not work with single characters -- it works with entire null-terminated character arrays. If you want to copy just a single character than simply use the = assignment operator. post[j] = in[x];

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

google for "network sniffers" and you might find some source code, but don't count on it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post the relevent code here that you have a question about. Most people won't download and unzip that file on their computers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>my compiler (bloodshed's dev-c++ v4.9.9.2)

Upgrade to Code::Blocks and MinGW compiler because its more current then the version you are using


>>int printBoard(const int[][]); //prototype

Change that to remove the const attribute. With 2d arrays the second array can not be left without a size. int printBoard(int[][size]); //prototype

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I guess that _getdirves() reutnrs a bit mapped integer of the drive letters on the computer. So that the first bit is drive 'A', the second is drive 'B', etc.

char path[255] = {0};
unsigned int get = _getdrives();
for(int i 1; i < 26; i++)
{
   if( get & 1 )
   {
        path[0] = 'A' + (i-1);
        strcat(path,":\\*.*);
        // do other stuff here
   }
   get >>= 1;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>yea so why it isn't working?


It does work. Since you didn't post the contents of that vector we have no idea what your program is comparing. compare() is case sensitive -- "Now" is not the same thing as "now" or "NOW".

Myself I would use the substr() approach, but compare() is ok too. So it boiles down to personal preference.

int main()
{
    vector<string> myvector;
    myvector.push_back("Now is the time");
    myvector.push_back("for all good men");
    myvector.push_back("to come to the aid");

    string number = "for";
    int x = 1;
     if( number.compare(0,3,myvector[x],0,3) == 0 )
         cout << "Yes\n";
     else
         cout << "No\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So what's your question? We are not going to write your program for you. Compression algorithms are much more complex than what you posted. For example you can get free Zlib source code here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've only seen it used with *nix compilers, but if yours supports it then it should be ok. The main thing is to use a recursive function call when a directory is encountered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please re-read my previous post, which I just now changed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is lines 4 and 5 are incorrect. Remove the = in those two lines.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>EDIT: Just saw AD's post: No.. please.. don't disable warnings.. always compile with all warnings and make sure to get rid of them all. I know Microsoft's compiler is particularly nagging, but still, treat warnings as errors because they often hide a subtle one.

In most (all other) cases I would agree with you. But the C functions are not depreciated by either C or C++ standards, and that's the only ones that count. Microsoft does not set the standards, even though they may be a major contributor. I don't mean to say there is anything wrong with using strcpy_s() instead of strcpy(), just that strcpy() is more convenient and can be just as safe.

There are a number of instances where character arrays are more convenient than std::string. structures, binary files, databases, and socket programming are just a few of them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>But my compiler complaining me a warning saying strdup and strcpy both are deprecated

The only compiler that complains about that is Microsoft. AFAIK they have not been deprecated in either the C or C++ standards. So I just use a pargma to remove that warning #pragma warning(disable: 4996)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It appears the problem is that new numbers are being added to the head of the list, and you need them added to the tail. Change lines 44 and 45 to add the new node to the end of the list.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What compiler are you using? Looks like os is MS-Windows but using *nix opendir() and associated functions.

In any event, you don't need to use chdir(). Just call list() recursively for each subdirectory that's encountered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is how NULL is defined by vc++ 2010 express in stdio.h Note that it's defined differently for c++ than it is for C.

/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post newest code and this time use code tags.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>int age[3] = { 18 , 40, 65 };
Why are you initializing it with some dummy data? Just initialise the array with all 0s int age[3] = {0}; >>int randomage = rand() % 3; //return a number from [18,75)

That's a number between 0 and 3, not 18 and 75

>>for( int i = 18; i < 75; i++)
The array only has 3 elements. You are trying to use the age range as the index into the array. What you want is this: for(int i = 0; i < 3; i++)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 21: chv is an uninitialized pointer. You have to allocate memory fo it before that loop.