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

RIP -- she died recently at young age of 85. Those in my age group will remember her as the sweeet little curley haired girl in movies. She made a couple movies during here teenage years, but her movie career ended after that. After adulthood she became American Czechoslovakia. You might say she now rides on the Good Ship Lollypop.

Link for full details.

ernie.cordell commented: I hope she gets animal crackers there. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you have a windows repair disk? Did you make backup before you started screwing up your computer?

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

You need to pass Number to assign() by reference, not by value so that assign() can change the structure that is declared in main().

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

The difference between char *str="Hello World!!";. and char str[]="Hello World!!";. is that char* str is just a pointer into read-only memory where the string "Hello World" is actually stored, it's contents can not be changed. char str[] makes a copy of the string and puts it into read/write memory where you can change the string nowever you wish -- you just can't change the length of the string. Using gets() on char str[] works just fine as long as you don't enter more characters then there are in the original string.

You can't use char* str with gets() because char* str had no memory allocated to it. Where is gets() supposed to put the characters you type? It is YOUR responsibility to entire that the string you pass to gets() has enough memory allocated to it to hold all the characters you want to type. And that is a big big problem with gets() and why everyone discourages it's use in most programs. instead of gets() use fgets() instead because fgets() limits the characters you type to the size of the buffer.

cambalinho commented: thanks +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can easily find out the size of an int by printing sizeof(int) -- but to answer your question, on most 32-bit compilers sizeof(int) == 4. If you are accustomed to using Turbo C, that is a 16-bit compiler and sizeof(int) == sizeof(short) == 2. But on most modern compilers sizeof(int) is not the same as sizeof(short). It's never a good idea to outguess the size of integers becaue it can vary from one compiler to another, and the C standards make no such assumption.

printf("sizeof(short) = %d\n", sizeof(short));
printf("sizeof(int) = %d\n", sizeof(int));
printf("sizeof(long) = %d\n", sizeof(long));
printf("sizeof(long long) = %d\n", sizeof(long long));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Banfa -- gives very good explanations

http://www.daniweb.com/members/724268/Banfa

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

Lets say you have two files A.cpp and B.cpp, each of them use the functions that are in functions.h. If you put the code directly in fuctions.h the linker will spit out duplicate function error messages for all the functions in functions.h. That's the main reason to put the functions in functions.cpp and the prototypes in functions.h. Can you immage the errors the compiler will spit out if you have 100 *.cpp files in the same program and each of them include functions.h???

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

Delete both lines 10 and 11. Line 11 will never be executed because of the k < k condition in likne 10.

Here is a good article about loop unrolling.

One of the optomizations you would make is to calculate i*j*idaonly once within a loop, save the result in another variable, then use that variable everywhere else i*j*ida appears in the loop.

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

maybe something like this:

void mystrcat(char* dest, const char* source)
{
   while(*dest)
      dest++;
   while(*source)
      *dest++ = source++;
   *dest = 0;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just multiply the parameter by 100 to get a whole integer, then return the line in the file which has that many digits. Is the file already sorted in numeric value in descending order? If not, then you will probably have to read the entire file and pick out the lines that you want.

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

Wife to husband: Do you rememember last month when two men tried to kidnap me?

Husban: Yes, and an hour later they returned you with their apologies

Wife: I only reasoned with them.

(Diablo 3)

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

SOCKET shold be an int, not char because it's value can be a lot larger than what an char can hold.

The file that contains SOCKET declaration is probably not reachable to the *.c file or there could be an #ifdef around it.

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

HereClick Here you go.

rubberman commented: Ain't Google Search great!? :-) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ is probably the most used by good game developers, but it's not the easiest. IMO the easiest would be VB.NET because it's graphics are much easier than other languages.

I'm not a game programmer, but if I were I'd spend a lot of time here and on google.

where should i go for good graphics?

Draw them yourself.

DeanMSands3 commented: Because AD is always awesome. +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This question has been asked and answered over a million times. Why don't you just use google to get your homework done.

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

To do it in either C or C++ you need to read some tutorials about socket programming. There is a difference between MS-Windows and *nix sockets, so you first have to determine which platform you are writing for. Here are some google links that you might find helpful.

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

this one works as expected.

void sortstudents()
{
    clearWindow();
    FILE *fp;
    fp = fopen("record.txt", "r");
    if (fp != NULL)
    {

        //stud *arr = (stud *)malloc(chunck);
        stud starray[25] = { 0 };

        int count = 0;
        while (fread(&starray[count], sizeof(stu), 1, fp) > 0)
            count++;
        fclose(fp);

        gotoxy(37, 12); printf("The record is Found");
        gotoxy(37, 13); printf("--------------------");
        gotoxy(37, 14); printf("ID: %i", *starray[0].id);
        gotoxy(37, 16); printf("Name: %s", starray[0].name);
        gotoxy(37, 18); printf("Term: %d", starray[0].term);
        gotoxy(37, 20); printf("Score %: %0.1f", starray[0].gpa);
        gotoxy(37, 22); printf("GPA: %c", starray[0].grade);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 300: The file pointer is at EOF when that line is reached because of lines 277-288: there is no need for that loop so just delete it. Besides, there is a lot easier way to get the number of characters in the file. But that function doesn't need to know how big the file is.

After making the changes I mentioned, that function should look like this:

void sortstudents()
{
    clearWindow();
    FILE *fp;
    fp = fopen("record.txt", "r");


    //stud *arr = (stud *)malloc(chunck);
    stud starray[25];

    int count = fread(starray, sizeof(stu), 100, fp);
    fclose(fp);


}

Note that the array is local to that function, so it will get destroyed immediately when the function terminates. If you need the sorted array somewhere else in your program then you will have to pass it as a parameter into the function instead of declaring it locally.

The next think I suppose you need to do is sort the array. There are a lot of sort algorithms, some more difficult than the others. I'd suggest you use the bubble sort algorithm becaue it's the easiest to code. You can easily find it by googling for "bubble sort algorithm".

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

You'll get better answers if you post in the corrct forum instead of just posting in any random forum that suits your fancy. Would you go to a butcher to ask a question about fixing your car? He may or may not know the answer, but it would seem more reasonable to go to a mechanic for that kind of question.

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

How did you write the records? Did you use fwrite()? If you did, then just use fread(). The parameters to fread() are the same as fwrite()

struct student students[100];
int count = 0;

while( fread(&students[count],sizeof(struct student),1,fp) == 1 )
   count++;

// Another way of doing it is to attempt to read them all at one time
// fread() will return the number of student records actually read.

count = fread(students,sizeof(struct student),100,fp);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to post a couple lines from the file so we can see how it is formatted. But generally you would want to read each field into it's appropriate structure element. The easiest way to do it is calling fscanf() instead of reading the file one character at a time like you are trying to do.

For example, it might be read something like this:

     FILE* fp = fopen("students.txt","r");
     struct student st;
     struct student starray[100];
     int numStudents = 0;

     while( fscanf(fp,"%s%s%d%f%c",st.id,st.name,&st.term,&st,gpa,&st.grade) > 0)
     {
          starray[numStudents++] = st;
     }

But, of course, the above may be all wrong, depending on how the file was written.

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

This is C# forum, not java. For java questions post in the java forum. And ... do not hijack someone else's thread to ask your question but start your own thread.

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

Before comparing a pointer to NULL you have to initialize them to null when you declare the pointers (or at least some time before using them). If you don't then the the value of those pointers are whatever happens to be in memory at the time they are declared, which may or may not be 0.

char *strings[100] = {0};

The above will set all 100 pointers to NULL (which is the same as 0)

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

person.name[i]

You need to index person, not name

person[i].name

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

In a M by N array, where M is the number of rows and N is the number of columns, the array has these coordinates

Upper left: 0,0
Lower left: (M-1),0
Upper Right: 0,(N-1)
Lower Right: (M-1),(N-1)

The way I understand your assignment is to find the sum of those four cells.

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

line 11: remove all the spaces.

haider885 commented: thanks....its working now +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes. If you want it in another thread then you have to specifically create a new thread, then start a new instance of the class from within that new thread. New threads are never ever started all by themselves, you have to do it yourself.

Read this article and this about how to create a thread.

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

You can usually find online help with most c++ functions and classes by googlein for them. In this case, google for "c++ std::string" and this will be the first hit you see.

Once there, click the link (constructor)

Next, look down the page at Parameters and you will find this (where n is the first parameter and c is the second):

n
Number of characters to copy.
c
Character to fill the string with. Each of the n characters in the string will be initialized to a copy of this value.

In otherwords, line 14 is creating a std::string object of 1 character and initializing it with whatever *being points to.

lines 19-22 loops through the rest of begin, but to me that loop isn't doing much of anything. I don't see any purpose of that loop.

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

Isn't that how it's supposed to work? When scrolling through a thread only the <DANIWEB> link and search bar are fixed. The other lines are also fixed when scrolling through menus.

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

a+b adds the two ascii values. Look at any ascii table and you will see that 'a' == 97 and 'b' == 98, so a+b = 97+98 = 195. Now look again at that ascii table and find the character whose ascii value is 195.

What you want to do is to save them in an array of characters

char array[3]; // room for 2 characters
array[0] = 'a';
array[1] = 'b';
array[2] = '\0'; // string null-terminator

cout << array << '\n';

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

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

If you have not yet studied structures then declare two arrays, one for 10 student names and the other for the sections. This assumes the names book1, book2, etc never change, so there's no point in storing those strings. If, however, those names can be different for each student then this array won't work because it can't store the names.

char student_sections[10][5][1];
char student_names[10][20];

A more robust solution would be to use a structure and make an array of structures.

struct course
{
   char name[8];
   char section;
};

struct student
{
   char name[20];
   struct course courses[5];
}

struct student students[10];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What event is supposed to cause the program to run? If the program only needs to run once or twice a day then use the operating system to schedule it as G_Waddell suggested 2 days ago.

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

A cat has 9 lives -- what has more than 9 lives?

Answer:

Frogs because they croak every night. (Duck Dynasty)

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

@mike so simply by using static in every function we mean that we want this variable to be related to the function only

No -- variables declared within a function are never visible to other functions, and they are auto destroyed as soon as the function returns to it's caller. Making variables within function static means that the variable will hold it's value from one function call to another, they are not destroyed when the function returns like non-static variables. You can easily prove this to yourself by running the following program

int foo()
{
   static int x = 0;
   cout << x << '\n';
   ++x;
}

int main()
{
   for(int i = 0; i < 10; i++)
      foo();
}

Now, run the same program again but this time remove the static keyword. You will see the value of x is always 0.

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

Not that I know of, but you can get the text itself. The size of the rectangle would depend on the font being used.

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

Technically me can be correct as well :

Here are the rules, which are pretty much the same as you stated.

diafol commented: good link +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I only used it once -- to generate an HTML page from the results of SQL queries. Don't know why they wanted me to use c++ for that instead of PHP. I was on a team of about 100 programmers, some c, some web. I'm not a web programmer so I can't explain it. AFAIK PHP can access SQL, sometimes easier than c++.

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

c++ is used for a great deal more than web development. Most PC games and desktop apps are written in c++. c++ can also be used as CGI programs (google "CGI programming")

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

Yes, loops can crash too, but everything else being equal recursion is more likely to crash than loops.

Like i said and i will repeat that again. There are situations recursion is the right way to go.

I absolutely agree with that statement, and I posted a link to one example of it.

Pretty and elegant codes are well contained and maintained, easy to debug than a worm code.

Yes, but not if pretty and elegent code crashes due to to finite memory constraints. There is no one right way -- it all depends on the situation, on the hardware and on the operating system. What may work perfectly fine on one operating system and computer may not work at all on another.

BTW: Don't try to win with Mike -- he never loses :)

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

Yea, the need to refresh after posting causes a few problems, at least for me. Try editing a post a couple times without refresh -- some edits will be lost and you'll have to do it all over again.

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

There are several ways to do it, but one way is: in a loop call getline() to read each line, then for each line read use stringstream object to split it into individual tokens. Post the code you have attempted and we can help you some more.

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

other than doing it myself!

Yes, that's what we want you to do, then ask questions about what you don't understand. We're not going to write the program for you, but help you to write it yourself. Give a man a fish and he will eat for one meal, teach a man how to fish and he will eat for life.

aroshkhan commented: agree (Y) :D +0
ddanbe commented: The proverb! +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what about storing data in a txt file with our own rules?

SQL is not the only kind of database -- in fact SQL can be very very slow when tables are large and using complex queries. Quite a few years ago I used Raima Database Manager, which, at that time, was not SQL. The advantage of RDM was that relationships were hardcoded at design time, so queries were very fast, several times faster than SQL databases. We didn't have huge multi-gigabyte files in those days so I don't know how it would perform in that situation.

You might want to do some evaluation yourself on what is better to use in your application -- you might be able to get fee evaluation version of RDM and an SQL database to test how they compare with plain-old-text files.

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

Why would you even want a cracked version when you can get it free (Express version) from Microsoft?

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

Before buying any book read the reviews at amazon.com -- they might save you some money by not buying a useless book.

For example:

You are looking at the most expensive book on C++ ever written, with nothing magical to show for that $110+ price [edit: with the fall semester underway, the price is now $135+].

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

Sometimes it's better to just start all over (I've done that before too). Create a new program and code what I said before. Forget about the menu for now, just get the code working that uses rand() to generate a single character using the forumla I previously posted.

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

add() is wrong

void add(struct node *newp)
{
    if (head == NULL)
        head = newp;
    else {
        struct node* temp;
        for (temp = head; temp->next != NULL; temp = temp->next);
        temp->next = newp;
    }
}

Another problem here:

scanf("%s", &rep);

rep is type char, not a string. scanf() will write at least two characters to that pointer, not just one (null string terminator because %s). Change to this:

scanf("%c", &rep);

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

The use of also is ok, but it should refer to something that was previously said. Since it doesn't, then also should have been omitted.

ddanbe commented: Thanks AD :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I actually wrote this program today just for fun -- as it turned out I wrote a function that generated a random char between two decimal values, then called it twice to generate 2 digits, twice to get two upper case characters, twice to get two lower case characers, and once to get a symbol. Then I called it 3 more times to generate any random printable character. Finally, call std::random_shuffle() to mix them all up.

But, I'm not about to post the code because that wouldn't help the OP at all to learn how to do it himself.

and I need to write a dictionary file.

I have no idea what that means. What is the file supposed to contain?