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

If you run the program I posted you will see that it sorts the file types in ascenting order.

That sort function sorts the strings. If you want to sort on size then you will have to change the sort function. In the sort function use < operator for ascending sort, or > operator for descending sort. You can have as many sort functions as you want to sort the vector on different fields.

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

That might work if you want to add the new node at the head of the linked list.

node *a = new node;
   a-> next = B;
   B = a;

If you want to add it to the tail then you have to search for the end of the list and add it there

node* n = B; 
while( n->next != NULL)
    n = n->next;
// now add new node
node* a = new node;
n->next = a;
a->next = NULL;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Congrats on your first star. :)

But ... but you already posted here!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
for(int i = 0; i < NumWanted; i++)
{
    // allocate a new node
    // attach new node to next pointer in previous node
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

LNK2005 means

The given symbol, displayed in its decorated form, was multiply defined.

You didn't post the exact error message so we can't really help you with that error.

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

>>Is there a way that base on the user input, you create how many nodes?

Yes. Use a loop. I am vague here on purpose -- think about it for awhile and you will come up with the answer.

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

Here is a complete example that I compiled and tested

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


struct fileInfo
{
	string fileType;
	int count;
	int size;
};
// Return whether first element is greater than the second
bool UDgreater ( fileInfo& elem1,  fileInfo& elem2 )
{
   return elem1.fileType  < elem2.fileType;
}

int main()
{
    vector<fileInfo> lists;
    // create a struct fileInfo object
    fileInfo info;
    // populate the fields
    info.fileType = ".CPP";
    info.count = 0;
    info.size = 0;
    lists.push_back(info);
    info.fileType = ".AAA";
    info.count = 1;
    info.size = 1;
    // add it to the list
    lists.push_back(info);
    sort(lists.begin(), lists.end(),  UDgreater );
    vector<fileInfo>::iterator it;
    for(it = lists.begin(); it != lists.end(); it++)
    {
        cout << it->fileType << " = " << it->count << "\n";
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To display the data

vector<fileInfo>::iterator it;
for(it = list.begin(); it != lists.end(); it++)
{
   cout << it->fileType << " = " << it->count << "\n";
}

Now to sort it, I did not compile or test this, so use at your own risk. google for std::sort and you will get lots more help.

// Return whether first element is greater than the second
bool UDgreater ( fileInfo& elem1,  fileInfo& elem2 )
{
   return elem1.fileType  > elem2.fileType;
}

int main()
{
....
    sort(list.begin(), list.end(),  UDgreater );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

char * strncpy ( char * destination, const char * source, size_t num ); No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num.

http://www.cplusplus.com/reference/clibrary/cstring/strncpy/

In your example strncpy(Hour, ConvertTime, 2); The length of ConvertTime is greater than 2, so the resultant string Hour will not be NULL-terminated. Hopefully, Hour was declared as char Hour[3]; so that it can hold the NULL terminating character.

See the example that was shown in the link I posted above how to fix that problem.

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

>>I am trying to print chars as numbers. I'm just wondering how to do this.

Easy

char c = 'A';
printf("%d\n", c);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>MyClass <DataType,int>:: search' : not all control paths return a value
Yes, tis true. The function can terminate without returning a value. When if ( (node->data).key == key) is fales, the else statement is executed and the function terminates without returning a value.

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

you coded it wrong

// create a struct fileInfo object
fileInfo info;
// populate the fields
info.FileType = ".CPP";
info.count = 0;
into.size = 0;
// add it to the list
lists.push_back(info);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

so your saying have 2 vectors that represent the number of files and the extension type?

I said no such thing. I said of a vector of structures. Each structure contains the file type and count, as well as whatever else you want it to contain. You can then sort that vector any way you want, by file type, by count, or some other field in the structure.

struct ftype
{
    std::string file_type;
    int count;
};

vector<ftype> lists;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have World Community Grid on my 4-core computer. It uses each of the cores to run different programs at the same time.

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

>>error C4716: 'addTITLE' : must return a value
>>error C4716: 'KeyLog' : must return a value

That means those two functions must contain a return statement. You declared the functions as returning an int but never stated the return value. If the functions don't need a return value then declare them as void, not int.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
cout << "Enter item\n";
cin >> node->item;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 20: the >> operator will not allow you to put spaces in the filename, such as path with spaces

line 22: fflush(stdin) is non-standard and not supported by may compilers. Unfortunately, there is no standard way to flush stdin. But if you use std::cin you can use cin.ignore(1000,'\n'); line 41: similar to line 22. use getline() if you want to include spaces.

line 47: don't use eof() like that because it doesn't work the way you think it does. Instead, control the loop with the return value of getline() while( getline(fin, line) ) lines 52-53: you can replace that with this one line transpose(line.begin(), line.end(), line.begin() toupper); from <algorithm> header file

line 55-56: same as above

line 58: what is str1? I don't see it has been set to anything. And to append one std::string to another just use its += operator line += str1; lines 60-70: I have no idea what those lines do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
ReadFile(com_port,&output,readlength,p_readlength,NULL);
std::cout << output<<std::endl;

In the first line the 4th parameter is nothing more than a pointer to the 3d parameter. declaring another pointer is not necessary. And do not put & symbol whan passing character arrays. ReadFile(com_port, output, readlength, &readlength, NULL); >>std::cout << output<<std::endl;
That's the reason for the garbage characters -- when ReadFile() returns the input buffer is not a null-terminated string. before printing the string either null-terminate it or print it one character at a time. readlength will contain the number of bytes that were read at the port. I would suggest you clear the input buffer before calling ReadLine()

memset(output, 0, sizeof(output));
ReadFile(com_port, output, readlength, &readlength, NULL);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

um, hello??

Howdy :)

Nick Evan commented: Hi! +16
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>The first one is a warning so it doesn't matter for now
You need to fix all warnings because most of the time warnings are really errors.

>> (title);
What the hell is that???

>> sprintf(oldtitle,"%s",title);
why sprintf()? If title contains spaces all oldtitle will get is the first word of that string. You probably want to use strcpy() instead of sprintf()

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

To be fair, it doesn't really matter whether he wrote all that code or not. He never said he wrote it.

IMHO he has jumped off the deep end of the swimming pool before he has learned to walk. My suggestion is to put this program aside for awhile and learn the basic of programming. After a few months' studying and learning you might be ready to tackle this program again.

jephthah commented: werd, dawg. thats what i was sayin' yo. :P +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After line 39 you need to add something to check if either of the two files have not reached EOF. My suggestion is to add two pointers, one for each file

char *p1, *p2;
...
  p1 = p2 = NULL;
  while( (p1 = fgets( s1, sizeof(s1), fp1 )) != NULL 
      && (p2 = fgets( s2, sizeof(s2), fp2 )) != NULL ){

    if( strcmp( s1, s2 ) != 0 ){
      printf( "\nFiles differ at line number %d\n", line );
      same = 0;
    }

    if( s1 == NULL && s2 != NULL ){
      printf( "\nFiles differ at line number %d\n", line );
      same = 0;
    }
    if( s1 != NULL && s2 == NULL ){
      printf( "\nFiles differ at line number %d\n", line );
      same = 0;
    }

    line++;
  }
  if( p1 == NULL && p2 != NULL)
  {
      printf("\nFile 2 is larger than file 2\n");
  }
  else if( p2 == NULL && p1 != NULL )
  {
      printf("\nFile 1 is larger than file 2\n");
  }
  if( same ) printf("\nFiles are the same.\n");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could create a structure then have a vector of structures -- I know std::sort works with vectors because I've done it several times. You have to write a function that take two arguments which are references to two of the vectors, and that function returns true if the first is less than the second. The function can compare whatever it wants as long as it returns either true or false.

The problem with this approach it that it isn't as efficient as a map. With vector, the program has to search to vector to see if an entry already exists, and if it does, increment the counter value in the structure. If it doesn't exist the it must add an entry to the vector.

The advantage of the vector solution is that the structure an contain anything you want. There is no limit to what information it can contain.

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

I don't know if maps can be resorted -- never tried it. You could give it a go using std::sort().

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

you don't have to sort maps -- map puts them in sorted order as they are inserted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Salem commented: It'll do +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can ya give me an insight about what's
vb.net and what's C# and asp.net
and how are they related ?

No I can't. They aren't related, other than being .net. AFAIK asp.net is used to build web servers, the other two are used to build application programs.

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

You have declared the array int grades[7] inside that function, so the function ignores the global array declared at the top of the program. Delete that array inside the function.

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

Did you check the spelling and capitalization as I suggested in my previous post ? FILE *cfPtr; and employeeHours (cfptr); -- they are not the same.

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

It doesn't work because you still have to write the functions that make the menu items do something. There is already diaplay_grade(), now you have to write other similar functions for the other selections.

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

On your Mobile 5.0 computer, after exiting the application check the computer's memory to see that it really exited and not just hidden. Also, make sure the program closes the port before exiting.

What is it trying to do in that tight loop ? Trying to open the port, but the CreateFile() failes?

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

>>For some reason when I compile the program it say I have not clarified my (cfptr)

You have to declare variables before they can be used. Check the spelling and capitalization of that variable carefully.

There are a lot of other problems in your program related to misspelling variables names. Try not to be so careless with them because the compiler will scream at you.

About opening the data file. Which function(s) are you referring to?

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

line 47: breaks are not used with if statements, so delete them.

What don't you understand about your program?

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

You are going to have to tell us what that program does not do that you want it to do, or what it does wrong. We are not clairvoyant nor are we mind readers.

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

line 19: missing closing } character to close out that if statement

line 49: incrementing that pointer just destroyed the memory that was allocated on line 42. You must never change an allocated pointer. If you want to use pointer arithmetic (increment and decrement) then use a different pointer. I would suggest you don't use a pointer at all, but use the loop i counter to index into the array.

line 46 and 47 can be combined: fscanf( file, "%f", &array[i] ); The next problem is what are you doing to do that that array after reading the data? You have to save it somewhere so that it can be used again later in the program.

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

simple example

#include <map>
#include <string>
#include <iostream>
using namespace std;


int main()
{
    std::map <std::string, int> m;
    m["cpp"]++;
    m["exe"]++;
    m["exe"]++;
    m["exe"]++;
    m["exe"]++;
    m["ppt"]++;
    m["ppt"]++;
    m["ppt"]++;

    std::map <std::string, int>::iterator it;
    for(it = m.begin(); it != m.end(); it++)
        cout << it->first << " = " << it->second << "\n";

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

Which chapter would that be? Of course there is nothing wrong with you reading the chapter yourself.

The instructions seem pretty clear to me

  1. Create the starter program with main() function
  2. Add a character array that has 3 rows and 30 columns
  3. Create an iostream object, open the data file and read the rows into the array.
  4. Loop through the character array and, for each month, count the number of R's, S's and C's.
  5. Display the report on the screen using std::cout.

If you don't know how to use ifstream then you can search for example code -- there is lots of it all over the net and even here at DaniWeb. Learn to make google one of your best programming buddies.

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

nice assignment, now what do you think we should do for you?

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

add this just after the using namespace std; statement: #pragma warning(disable: 4996) and the compiler will not produce warning number 4996

The error is on line 571 (as you posted it).

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

and i also added the code that you suggested, although im not sure what it does lol

What it does is move the line read from the file into the structure. There is no point reading the file if you are not going to do anything with the data.

I have taken out the code for the counter, should i put it back in?

No -- variable count is ok too.

all it did was save the count in a text file, so when i reopened the console, it didnt reset to 0

Actually saving count to the text file. Just count the lines as they are read is all that you need to do.

And you need to increment the value of count on line 44, which I think I forgot to do in my post.

Does that code you gave me load the information from the text file back into the array?

Yes

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

That might work if you make them pointers.

int main()
{
Base* aBase;
A* aA = new A;;

aBase = aA;
}

now somewhere else in your program

void foo(Base* b)
{
   A* a = b;
   // do something with poihnter a
}
int main()
{
    A* aA = new A;
    foo( aA );
 
}

>>Is this right?
I don't know -- that is a mighty strange way to create a linked list.

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

new node()???????????
I think you mean new node; there

Either construct is correct. I don't use () if there are no parameters to pass but I know several people who do.

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

>>Apparently I can and so can annyone. I did solve my problem, here it is:

NO YOU DIDN'T. You put C code in a C++ program, not the other way around. C++ supports most C, but C supports nothing from C++.

>>This is the proof.
You proved nothing.

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

>>I also don't know why every place there is a colon and capital D I am getting an emoticon.
Yea -- click the Advanced button, scroll down to the checkbox Disable Smilies In Text. I fixed it for you.

I think there were lots of changes between 2003 and 2005/8. Never used 2003 so I can't help you.

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

you could use a union, in which case either pointer could be used

struct d
{
    union
    {
        struct A* a;
        struct B* b;
    };
};

Or maybe use a base class that is common to both A and B

struct Base
{
    int x;
};

struct A : public Base
{
    int a;
};

struct B : public Base
{
    int b;
};


int main()
{
    struct Base* c;
    struct A* a = new A;
    struct B* b = new B;
    c = a;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Looks like all it has to do is return the value returned by getPoly()

[edit]What ^^^ said too :) [/edit]

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

>> // not sure what goes here

Neither do we since you didn't post enough of the class to know what is supposed to be returned. Its supposed to return a reference to something, but we have no idea what.

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

given the lack of any sort of question or comment or request, i suggest it be moved to the "trash" board.

or is our daniweb psychic logged on?

LOL :) I think the question is in the comments

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

>>Do you know how to do what the first post asks, but in c++ language?

Yes I do. Do you know how? (hint: first learn to ask the right questions.) If you know c++ then the conversion should be pretty easy for you.

delete lines 3 to 7, and replace them with ofstream object.