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

why are lines 30 and 31 identical? you should delete one of them.

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

1. don't use the version of fstream and iostream that have .h extension -- they are depreciated (obsolete) and were replaced by versions without extension. But if you are using an ancient compiler such as the original Turbo C++ you may have no other choice.

2. Don't use global variables for the stream class. Make it local to the function in which it is used.

3. Never erver use void main(). Always use int main instead. See this thread for more explaination about that.

4 The program didn't work because your compiler probably produced an error or warning that you ignored. Never ignore warnings because most of the time they are really errros. Example: a == "Hello.txt"; is an error that you should have corrected.

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

>>I'm getting this error from this code
what line number contains the error ?

>> do you guys also work in multiple files?

Yes, my projects at work consist of several hundred files where the implementation code and header file of each c++ class are contained in their own files. This makes maintenance a lot easier than having all million lines of code in one file.

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

vijayan121, I don't think ifstream works for files over 2GB, which mine is. (7GB)

If this is on an MS-Windows machine, them you may have to use win32 api file i/o directly on that large a file. See CreateFile() to open the file, and ReadFile() to read its contents. All those functions can work with huge files.

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

>> strncpy(who,huj,300);
This line is probably causing the problem. each element of who can only contain 100 characters and that line is copying up to 300 characters into it. Won't fit.

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

The easier way is to divide by 10000 and take the remainder

int seed = num % 10000 ;

OMG Yes that is a lot easier :*

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

. any suggestions?

try vijayan's succestion :)

>>The code runs ok in his machine
And I've heard/said that one a million times too :D

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

>>what the int main(); thing is about

all functions have a return type such as int, char*, double, etc. main() is a special kind of function and is the only function required by the C and C++ standards, and it is required to return an integer back to the operating system. That return value is often used by other programs to determine whether it completed successfully or not. There is no standard value that main() must return other than it must be an integer. But by convention 0 means successfuly completion and any other value means failure.

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

how about some animated smileys :?:

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

does second.find(Name); return an iterator of the correct type? such as std::map<std::string, c_PerformanceMeasurement>::

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

which version of Turbo C are you using? and which version of MS-Windows? It sounds like the compiler may have changed your window to full-screen command prompt. Did you try just pressing the <Esc> key ?

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

>>Extract the lower 4 digits of the result produced by step 2.

The easy way is to convert the number to a string then only use the last 4 digits.

int num = 12347;
char buf[10];
sprintf(buf,"%d",num);
int seed = atoi( &buf[1] );
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

my guess is that you forgot to include one or more header files. You should post the line(s) the compiler is complaining about.

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

where's the laughing smily :@ Otherwise, I :* them. :cool:

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

>>i always think that a good programmer is not suppose to take that much time to complete the program :D

I whish that were true --

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

you must mean Turbo C++, not Turbo C. But I don't know why you can't code it in c++. If you expect to get that project done in a week then you will have to work a lot of hours each day -- not much time left for play.

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

probably are no such tutorials, but you can search their web site.

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

not likely to be your compiler but the program you wrote.

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

>>It works, I just want to know if I'm answering the question correctly?

If the program works ok, then yes you probably answered the problem correctly.

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

See the OPENFILENAME structure and GetOpenFileName() function They already have the options you want.

And here is a drive picker MFC class. Download the source code for this project and it will show you how to get the list of drive letters that are available on the computer.

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

just put the char array variable name inside atof()

char num[] = "99.0";
float n = atof(num);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

600 non-M$ products seems pretty good for an os that has only been officially released for a couple months.

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

what version of vista do you have ? I'm using Home Premium and SQL Server Express installed and starts without any problem. I also have VC++ 2005 Express, but don't know if that is a prerequisit to the sql server.

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

I think he wants to duel boot xp and vista. I didn't have any problems doing that but I had xp on drive C and installed vista on drive D (two physically different hard drives).

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

I get an error:

did you include algorithm header file ? what compiler are you using ? some compilers may need the :: global scope operator in front of toupper function name transform(response.begin(),response.end(),response.begin(), ::toupper); If that doesn't fix it then you may need to repost your current code.

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

Here are two more examples. There are others in Code Snipets board too.

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

works ok for me -- here's the code I changed

#include <algorithm>
<snip>

      cout<< "Do you want to enter a different percentage? Yes | No  "  ;
      cin >> response;
     // convert to all upper-case        
      transform(response.begin(),response.end(),response.begin(),toupper);        
       if (response == "YES" || response == "NO")
       {
                good = false;
       }
       else
       {
                cout<< "Invalid response   " << endl;
        }
               
        if (response == "NO")
        {
                    break;
        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

its stilll slow :(

Maybe its because you live on the other side of the pond then we do -- all those bits and bytes have to travel through thousands of miles of water in order to get to your house. And you know how bullets travel slower in water than in the air. :cheesy:

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

am i the only one who doesnt mind the ads here by the way?

Nope. I don't even notice them. But I understand how people with slow dial-up modems might object because the ads would probably slow down page load times a lot.

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

post code please.

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

what text file are you using for your tests? Did your instructor give you one or did you make up your own ? If you can make up your own I would use a text file that you may already have lying around on your computer. That yway you can have something like this

c.exe Hello Worlds file.txt

instead of just nonsense characters.

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

It seems there may be some ambiguity in the requirements (and that occurs all too often) I assumed "occurrence of the characters" really meant the string supplied by the first argument. Example: replace all occurrences "Hello" with "Hello World". When the length of the string in the 2nd argunment is different than that in the 1st argument that means the size of the result string may be different than its original size by either shorting or lengthing the text read from the file.

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

maybe flip is like giving someone the bird :mrgreen:

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

>>Does using 64 bit processor or other compilers have effect?

The compiler and processor are not relevent to memory leaks. Offhand I'd say your program has buffer overruns somewhere.

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

>>I need help finding a gui library for c/c++
It's called the win32 api functions and is supplied with all Microsoft compilers as well as most other compilers that target the MS-Windows operating system. There are about 100 or so libraries included in it.

Here is a popular tutorial to get started with win32 api programming.

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

I’ve worked it out now so don’t worry about it!

ta

Yea I know all about that type of problem, I just spent three days trying to find one like that in my own program.

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

First learn how to properly format your programs. I helped you out this time by doing it for you just so you can see how it should be done. There is absolutely nothing wrong with being generous with spaces and line feeds -- makes your program a lot easier to read.

>> it gives error
what error? I suspect it might be because you did not include <string> header file.

>>and how to implement the other required derived class student and instructor
here is how to declare Student. Other derived classes are the same format.

class Student : public Person
{
   // your code here
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

apparently the value of response is something else -- maybe you typed "YES" (all upper-case). The best way to handle that is to convert response to all upper case letters so that you don't have so may variations of the same string. That way all you have to do is compare with "YES" or "NO".

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

>>//check whether the initial and replacement strings are of same size.

That check does not meed the program's spefications -- there was nothing in the assignment you posted that said the replacement string must be the same length as the search string.

>>creat( argv[3], O_WRONLY

why are you using those deprecated functions? Use standard C FILE and associated functions.

>>gets(buffer);
never ever and at no time use gets() because it can cause your program to crash big-time. Use fgets() instead to limit the keyboard input to the size of the input buffer.

Please please format your code so that you and everyone else can read it. I was going to add the code tags for you but it was just too badly formatted for code tags to do any good.

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

There is no one tutorial for all win32 api functions because there are hundreds, if not thousands, of them. Tutorials are ok for very beginners, but you will quickly out-grow them and will need to invest in a few good (but expensive) books.

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

MSDN will normally tell you what header files and libraries are need for a given function. goto www.microsoft.com and search for the function name.

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

you have not changed anything. you have to check for NULL AFTER calling strpbrk(), not before. And you also created an infinite loop because the value of i counter is never changed.

>>pch+1
that is wrong -- why are you adding 1 to a pointer value????

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

Sorry, I can't help you there -- I don't know the first thing about it. google around and you will more than likely (??) find something.

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

If you want to read the file like that you will have to write an overloaded extraction operator for your structure because the standard stream classes don't know how to read structures. Or if you don't want to do that, then extract each element individually, something like this: I don't know what the structure looks like so I'll just make up something.

infile >> students[i].name >> students[i].address;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

not buffer overflow -- you are not checking that strpbrk() returns a NULL pointer, which it can if the string does not contains the characters.

pch is a 2d array of pointers, so if strpbrk() returns NULL that printf will fail. The format specification in printf() is incorrect too -- should be "%s", not "%c" because pch is a pointer to a string, not a single character.

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

You failed to say what the problem is, but if you want to read one column at a time then using the extraction operator like that won't work right with csv files because columna may, or may not, be separated by white space (spaces and/or tabs). The csv files I've worked with had a comma between each column. So you would probably want to use the getline() function so that you can specify the character that terminates a word.

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

create a bootable floppy and look to see what files are on it :rolleyes:

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

check the client to see if it is sending the '\n' character. maybe it just terminates and doesn't send it. Also, your server program should check for buffer overflow before adding a new character. Terminate the loop if the buffer fills up.

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

you declare a 2d array of strings like this

const int ROWS = 255;
const int CHARS_PER_ROW  20

char array[ROWS][CHARS_PER_ROW];

then it looks like this

char get(char array[ROWS][CHARS_PER_ROW])
{
    ifstream fin("input.txt");
    if( fin.is_open())
    {
         int row = 0;
         while( row < ROWS && fin >> array[row++] )
            ;
   }
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ancient, I think you hit up DaniWeb at a time when the database server was copying an SQL backup to the web server. The other day I was pulling one of my infamous allnighters (redoing the layout of the blogs, tutorials, code snippets, etc) and I happened to notice a 5 am - 6 am slowdown. I've already told blud about it.

AhHa! And I was beginning to think I was getting senile in my old age:mrgreen: