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

just use stream's >> operator on an integer, it will convert negative sign for you to make the value of the integer negative.

ifstream in("file.txt");
int n;
in >> n;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what do you mean by "low privilege" ? Low executation priority ? If so then forget it because all that will do is cause your server to get little, if any, cpu time even when needed. Better to put the server into a wait state until an event occurs, such as receipt of a message from clients to do something.

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

> The first time that January 1 will fall on a Sunday is the year 4300.

Oh wait, don't you have an official holiday on 1st January? ;-)

And you don't ??? Bummer!

~s.o.s~ commented: Yes, at least Software Engineers here do have a day off on 1st. :-) +26
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> telling you if you give $19 , she will tell you 6 lucky numbers which can make you win million dollers

:) what a scam ! does she guarentee those results?

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

Welcome to DaniWeb John. There are several of us old-timers here.

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

closed

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

>>At one hand pretending to be concern of the imposed socialism that its invading this country at a monumental stride

Yes I am concerned about it, but what are the alternatives? You mentioned one in a single sentence. That has been tried several times before and didn't produce desired or lasting results.

>>Wherever it blows there you go
Quite possibly :)

>>Do you really believe that reducing government in the life of people

Deregulation is what got is into this mess. People with power just can't be trusted to do the right thing, they have to be watched like a hawk. Unfortunate, but true.

>>and making it subject to accountability
Obama is trying to fix that too. Bush spent $350Billion with no accountability and we now have not a single thing for all that money.

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

No tax cut has put a police officer on the beat; no tax cut has put a teacher in the classroom. You are spouting nonsense. I want to hear what your plan is, how it will get the economy out of this crisis.

Amen to that :) :)

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

Check out Data Point

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

you can't use the comma operator to declare variables of a different types -- they must all be the same type. So I'd code it like this (making the iterator global to the function instead of just the loop):

list<int>::iterator itr = bob.begin();
for(int i=0;i<3 && itr != bob.end();itr++,i++)
      cout<<*itr;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh you want something like a gui Progress Control, but just for text mode program. You would probably want to put the code for that in another thread while the main program (thread) is doing other things.

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

its the same as sorting integers. If they are c style character arrays then call strcmp() instead of the < or > operators. If std::string then you can use the same operators. Otherwise there is no difference.

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

By the way I just want your opinion; isn't it a problem to have a class Y already created in class X?


King Regards.

No, its a common occurence -- programmers do that frequently.

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

1) struct L1 and struct L2. Since the structures are identical except for the names you could just one struct for both purposes. No need to declare two structures that do the same thing, just reuse one struct.

2) >> if(strcmp(a->string,b->string)) {

strcmp() returns 0 if the two strings are identical. That should be coded like this: if(strcmp(a->string,b->string) == 0) {

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
char **array; // A 2d array pointer
int nof; // No of files required
int noc; // No of characters required in the string

// Scan values of nof and noc

array = ( char * ) malloc ( nof * sizeof( char *));

for(i = 0 ; i < nof ; i++ )
{
        array[i] = (char *) malloc ( noc * sizeof( char ));
}

@ANCIENT DRAGON

Please comment on this post. I have some minute doubts which your comments may clear.I mean how would linked list help to solve the above problem in a better way?

That code probably works ok, but only for one file. That matrix needs another dimension if it to work for more than one file.

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

I got it wrong again? I thought that was 100 strings.

Nope. its 15 strings as I said before. If you want 100 strings for 15 files, and each string has a maximum of 79 characters+terminator, then do this: char arry[15][100][80];

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

Exactly how is each file written? can you attach on of them to your post. By noc (number of columns) I was thinking of a matrix something like and excell file where you can have X number of columns and each column can contains strings of unspecified length. Something like this, which has 3 columns of text strings.

C1                       C2                    C3
One two three     four file six       seven eight nine
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> X newX = new X();
wrong syntax. should be X* newX = new X;

Comatose commented: Great Minds +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might investigate Boost libraries. I'm not sure they have just what you are looking for.

Or try this

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

Do you need all those files in memory at the same time? char arr[15][100] will only hold 15 strings, each string can contain a maximum of 99 characters + null terminator. So about all you might get in that array is the first line of text that is contains in 15 files.

You could use linked list of linked lists instead of a simple array. With that the program can read the files only once and still get they dynamic allocations you are looking for.

For example you could use a structure something like this:

struct LINK
{
    void* data;       // primary data attached here
    viud* extradata;  // this could be another linked list
    struct LINK*next;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Very few Americans like socialism. And even fewer like the Bailout plan that is being formed in Congress. But what else can we do? I haven't heard of a single alternative and positive proposal. Doing nothing is not a viable solution because it will probably just make things worse than it is now.

And we can't point fingers just at the Bush administration -- this has been brewing every since Jimmy Carter. It is the "American Dream" that everyone owns their own home -- and a huge one at that. According to 2000 statistics the average size of the American household is 2.58 people. According to the National Association of Home Builders, the average home size in the United States was 2,330 square feet in 2004, up from 1,400 square feet in 1970. So why do people need such large homes when they can't afford the house payments ? And what do they do with those large homes once they become empty nesters?

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

In the news:
Citicorp Bank just bought a new corporate jet for $50 million with some of their bailout money.

due to bad publicity and public outcry that jet was cancelled.

I hope Obama makes those bankers pay back every penny or put them in prison for the remainder of their miserable lives.

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

you better hit that old geek..

Huh? Hit what ?

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

http://www.sciam.com/article.cfm?id=that-burger-youre-eating-is-mostly-corn

Surpise! Surprise! Surprise! Any farmer in the world could have told us that! Very few, if any, cows in USA are purely grass fed because they would starve to death.

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

closed

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

Microsoft stopped supporting makefiles beginning with VC++ 2005. Instead they have solution files which you can use to do command-line compiles. But first you will have to use the IDE to create the solution file. It also has its own version of make, but I don't recall its name.

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

Good for you :)

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

you also need to add the = symbol

char *point[]  ={
"This is One",
"This is Two",
"This is Three",
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 51 and 52: you can't use an ifstream (in_input) like that.

How do you distinguish boy names from girl names? Or is one colums boys and the other girls? After reading the file your program needs to scan through the list and count the number of times each name appears.

[edit]I went ahead and wrote the program (I'm not going to post it though). I found out that text file does not contain any duplicate names, unless of course my program is wrong. So I don't know how you can find the most popular girs and boys names [/edit]

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

If you use fstream its >> operator will skip all spaces and tabs for you, so that all you get are words.

ifstream in("in.txt");
std::string word;
while( in >> word)
{
    // do something with this word
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>anyone have any suggestions?

Post your complete program that illustrates the problem you are having, and also tell us what operating system and compiler you are using. It's possible you might need to call flush() at the end, such as cout << "Hi" << endl; (note that endl also calls flush() )

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

The loop looks ok to me. Remember, it is writing a binary file, not a text file, so you can't view it with programs such as Notepad.exe because they don't know how to read binary files.

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

>>So in C++, using Something like Unix Sockets or Winsock with C++ lets you use things like TCP/IP. But it only lets you connect to an IP within your router when its by itself.

False. Try making the address something like this: "http://www.DaniWeb.com" and you can connnect to it via tcp/ip.

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

>>while (tokenPtr!='NULL')

Remove the quotes around NULL. while (tokenPtr!=NULL) >>char checkCount[20];
You should make that a lot bigger. A 20 character sentence is pretty darned short.

Dontais commented: Great help, thanks Ancient Dragon +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10 is wrong. Why is value a pointer? From the class constructure it appears to be just a single integer, and you don't need a pointer for that

And get rid of those stars on line 10.

class box{
public:
         int value;
         box()
         {
                   value=0;
          };
          box(box &c)
          {value=c.value;};
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> First, I need help setting my char array defined in my class to "null" within the default constructor.

That's an easy one. All you do is flood the entire buffer with 0s.

class person                      //class of persons
 {
   protected:
      char name[80];           //person's name
      short age;                  //person's age
   public:
      void getData()              //get person's data
         {
         cout << "Enter name: "; cin >> name;
         cout << "Enter age: "; cin >> age;
         };
        person()
        {
            memset(name,0,sizeof(name));
            age = 0;
       }          
};

>>Second I need to know why my "for" loop for creating the 10 slots isn't working
The loop 0 to 9 is only 9 slots, not ten. The loop counter should count from 0 to 10.

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

>>I'm sorry, I didn't realize I couldn't upload the exe file - but I have it ready to email.
That's ok We don't want you uploading exe files because (1) they can contain viruses and worms and (2) we can compile the code ourselves on our local computer to test it out.

line 13: you should declare that as std::string not char. What you declared is just one single character and I doubt very seriously that anyone would name their baby a single character.

line 29: like line 13 all you declared was a single character. Why read the file one character at a time when you could read it one word or line at a time.

I see that each line of that text file contains 3 words: a number indicating rank and two names. That means what you need to do is to create an array of structures that contain those three items.

struct line
{
     int rank;
     std::string name1;
     std::string name2;
};

now you can create an array of the above structures struct line names[1000]; Now to read those structures into the array

std::string name1, name2;
int rank;
int count = 0;
while(count < 1000 &&  in_put >> rank >> name1 >> name2)
{
    names[count].rank = rank;
    names[count].name1 = name1;
    names[count].name2 = name2;
    ++ count;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One "change" the President has already made is conducting "town hall meetings". He had one just today in Elkhart, Indiana. To my knowledge no other President has ever done that. Usually when they get into the white house they just stay there.

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

ummmm....
how can you giv print to a single variable var with %s specifier???

Are you referring to the code I posted? I'm assuming var is an array of character arrays. It works because I used a loop that starts the variable i at 0 and increments it by one on each loop iteration. If you don't know about loops yet then you should read up on them.

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

wouldn't it have been a lot simpler to have coded it with a loop

int i;
printf(\nThe Result is : ");
for(i = 0; i < 7; i++)
   printf("%s ", var[i]);

>>whats wrong in my code.....
how did you declare and initialize array var ? Most likely the problem is uninitialized data.

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

Must be some other problem -- your program works perfectly for me using VC++ 2008 Express on Vista Home.

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

>>[pid,perm,dir,owner,group,size,date,file] = strtok(s," ");
What in the world are you trying to do here? strtok() only returns one string, not multiple strings.

pid = strtok(s," "); // first time
perm = strtok(NULL, " ");
dir = strtok(NULL, " ");
// etc etc for each of the others
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

we don't have enough of the code to tell you what is wrong.

lines 14, 15 and 16: you are making that much more difficult than it needs to be. puts(factsPtr->valuePtr->predicate); But without the rest of the code I can't be certain the above is actually correct. In any event it looks a lot simpler and clearer.

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

The President is not a miracle worker -- although I think that was one of his campaign promises :) All presidential-hopefuls promise things in their campaigns that they can't possibly fullfill, or that they later decide are unworkable. And I wouldn't be supprised if Obama is the same.

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

There is a great deal of truth in that video. I have dish network tv with over 100 channels to choose from, and there are days when there isn't a thing that I want to watch.

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

I'm up for other suggestions .... maybe people can win Featured Coder for writing code that does something creative ... ideas?

I'd have to vote for Narue as the first Featured Coder for her excellent work on the sticky posts in the c++ forum -- "How To Flush Input Stream" and "Read This Before Posting". I think she has even written a few blogs that are worthy of that distinction.

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

The Dude?

Yes, I'll vote for him too.

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

Orthodox Quaker -- but incorrect.

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

The main problem is use of globals. Delete the globals, delete unneded clear_foo() function, and your program works as you expect it to.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;


string int_to_s(int, string&);
string cypher(string);

int main()
{
    string foo;
    int number = 123;

    cout << int_to_s(number, foo) << endl;;
    cout << int_to_s(456,foo) << endl;

    return 0;
}

//Defined Functions
/*This bit of code comes from various sources on the web
 *that say this is easiest way to convert int to str */
string int_to_s(int num, string& foo){
    stringstream toString;
    toString << num;
    foo = toString.str();
    return foo;
}