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

This works, its essentially the same you had though. I added code to flush the keyboard buffer after each integer input. That may have been your problem.

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

class dt
{
public:
	int month,day,year;
	dt() {month = day = year = 0;}
};

class EmailHeader
{
public:
   string to;
   string from;
   string subject;
   dt Date;
};

//overloaded input operator
istream& operator>>(istream& is, vector<EmailHeader>& ehVec)
{
  EmailHeader headerInput;
  cout << "Enter an email Header: Ctrl-Z to quit" << endl;
  while(getline(is,headerInput.to))
  {
      getline(is, headerInput.from);
      getline(is, headerInput.subject); //crash occurs here on second iteration after the 
	  cout << "month: ";                                             // user hits the return key, so input below is skipped
      is >> headerInput.Date.month;
	  is.ignore();
	  cout << "day: ";
      is >> headerInput.Date.day;
	  is.ignore();
	  cout << "Year: ";
      is >> headerInput.Date.year;
	  is.ignore();

      ehVec.push_back(headerInput);
      cout << "Enter another email Header: Ctrl-Z to quit" << endl;
    }
  return is;
}

int main()
{
  vector<EmailHeader> emVec;

  cin >> emVec; 

  //other code
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

fgets() function leaves the '\n' in the input buffer, so you need to truncate it

printf("enter student ID:");
fgets(line, 255, stdin);
// truncate '\n'
if( line[strlen(line)-1] == '\n')
   line[strlen(line)-1] = '\0';
sprintf(filename,"%s.txt",line);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

but i though the entry in fopen has to be a either in "" or predefined?

It can be, but it can also be a variable, such as I posted. All it is looking for is const char*, doesn't care if it is a char variable or a literal string.

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

If you want to hire someone to write the program for you, then you could post in DaniWeb;s Job Offers board. I'm certain some students would be happy to make some extra cash.

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

well i used

fout = fopen("%s.txt", "w");

but how do i represet "%s.txt" as the user's input?

you already posted the answer to that question in your post #5. Just use variable filename

sprintf(filename,"%s.txt",line); // <<< from your previous post
fout = fopen(filename, "w");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Yes its possible to do.

2. Your posting in C/C++ board so why would you not want to use that language? (other languages are also possible)

3. Time consuming for who? Depends on the experience of the person writing the program.

4. Probably not.

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

Do it inside that if statement which is inside the do loop, something like this:

do {
  //check for . and ..
  if( strcmp(FindData.cFileName,".") != 0 &&
        strcmp(FindData.cFileName,"..") != 0)
  {
        ifstream in(FindData.cFileName);
        // do something with this file
        //
        // now close the file
        in.close();
        in.clear();
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If it succeeds, FindFirstFile() puts the filename of the first file into the structure. Your program is tossing that out by immediately calling FindNextFile(). I use a do loop here instead of a while loop

hFind = FindFirstFile("C:\\temp\\*.*", &FindData);
/*file process*/
cout << FindData.cFileName << endl;
// Look for more
do {
  //check for . and ..
  if( strcmp(FindData.cFileName,".") != 0 &&
        strcmp(FindData.cFileName,"..") != 0)
  {
       // do something
  }
} while( FindNextFile(...) );
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. The problem is that, just like all other objects, tempState is destroyed when it goes out of scope and fillDatabase() runction returns to whoever called it. If you do not expicitely code the destructor c++ will write one for you.

Why do you want tempState to live outside the function in which it is defined? If it is necessary, then I would either (1) add it as a member object of the class, or (2) pass a reference to the object as a parameter to fillDatabase().

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

post code -- we can't see your monitor. Is that file in current working directory? If not you will have to add the full path to the file.

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

Just noticed the problem in the attached file -- how "C and C++" is visible behind "Post since Last Visit". Using IE6 on XP

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

Again, use pencil & paper to write out the value on each iteration of the loop. If you know how to multiply something by 2 then this should not be difficult.

On the first iteration of the loop the value of i is 4. Then i is incremented to 5, then 6.

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


A good reason not to write system("pause") would be because it spawns a seperate process and troubles the OS since its a system level function. Why incur such overhead when the same can be done with getchar( ) .

Because in such a trivial program it doesn't make a hill of beams which way its coded. Creating another process is also trivial in most of today's computers; the os would barely even know the process is present in the system.

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

you need to add a line before the return to make the program stop so that you can read it. This will do ok

system("PAUSE");

Also, it isn't necessary to create a new thread just to correct a mistake. Just hit the Edit button -- you have about 5 minutes or so to make corrections that way.

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

I like
Deal or No Deal
American Idol
Survivor

Reruns:
Perry Mason
I've Got a Secret
Murder She Wrote
Diagnosis of Murder
Who Wants to be a Millionare
Dog Eat Dog

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

after each if statement, the grid should look like this:

a   b   c   d
5   2   1   3
2   5   1   3
2   1   5   3
2   1   3   5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> if(a=="^z" || a=="^Z")
you can't do string comparisons that way. You have to use C's strcmp() function

if(strcmp(a"^z") == 0 || strcmp(a,"^Z") == 0)

And the problem with the above code is that ^Z does not appear in the strings, and if they did it would not be as two ascii characters '^' and 'Z'. If you look at an ascii chart you will see that Ctrl+Z has a decimal value of 26 (the 26th letter in the alphabet).

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

bool z()
{ 
    char* a[10]={0};
    cin.getline(blah);
    if(a=="^z" || a=="^Z")
        return false;
    return true;
}

I get several errors on the above code.

Compiling...
test1.cpp
C:\dvlp\test1\test1.cpp(63) : error C2065: 'blah' : undeclared identifier
C:\dvlp\test1\test1.cpp(64) : error C2446: '==' : no conversion from 'char *' to 'char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\dvlp\test1\test1.cpp(64) : error C2040: '==' : 'char *[10]' differs in levels of indirection from 'char [3]'
C:\dvlp\test1\test1.cpp(64) : error C2446: '==' : no conversion from 'char *' to 'char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\dvlp\test1\test1.cpp(64) : error C2040: '==' : 'char *[10]' differs in levels of indirection from 'char [3]'
Error executing cl.exe.

test1.exe - 5 error(s), 0 warning(s)

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

use paper & pencil to do this problem. Final answer should be

a = 2
b = 1
c = 3
d = 5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can do this: char* ptr = const_cast<char*>(param;) , but that defeats the purpose of using const in the first place. Casting out the const should be avoided whenever possible.

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

Post Since Last Visit I don't think works correctly. I was here this morning, left for about 30 minutes, came back and that link shows posts made 2 hours ago.

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

40-60K is only starting salary. professionals with experience can often get a lot more than that. On the west coast (USA) you could easily get double that amount -- of course you will need it because it will cost tripple to live there :)

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

I'm from Utah -- 1300 miles (1400 km) from there :mrgreen:

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

Why do you need a toString function? cout will print out the integers quite well cout << tm->tm_hour << ;

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

In most cases a masters is sufficient, and in many cases that too may be over-qualified. All depends on your goals. A masters will probably pretty much guarentee you will advance your career into management position.

c++ certifications are not really worth a whole lot. There have been people who get certifications without ever toughing a keyboard or writing one line of c++ code. Formal education and experience are what employers look for.

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

also i think that the vector container has a sort function of his own, so you could you this to sort the strings!

The sort function is a function of STL, nor vector. Here is an example of how to vector of sort c++ classes

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

>>if i add one minute in the struct tm and then call mktime() it will fix all the other members?{
Yes -- that is what normalize means

time() function returns a time_t (normally unsigned integer). If all you want to do is add minutes, then just add (minutes * 60) to the value returned by time(), then call localtime() to get the structure.

Yes, you can do that in two functions if you want.

Here is basically the way you will probably want to implement the algorithm. Your function aa() might get the number of minutes from the keyboard, then pass that value to bb() to display the date/time.

int number_minutes = 1;
time_t today = time(0);
// add 1 minute to the current date/time
today += (60 * number_minutes);

struct tm* tm = localtime(&todlay);
// now just print out the struct tm
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The portable way is to use the functions in time.h. 1. get current time using time() function, which returns the number of seconds since some pre-determined data, normally 1 Jun 1970. '
2. call localtime() to get a pointer to struct tm, which contains each element of date/time as integers.
3. Add the number of minutes to the tm_min element of tm structure.
4. call mktime() to normalize the date/time. This function corrects all tm structure members.
5. using final version of tm structure to print out the results.

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

congratulations on meeting the 1,000 posts mark :)

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

Any idea why it is blank on my browser ? (see attached zip file)

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

I really was not trying to be rude -- I apologize if you took it that way. Since you write that much, like I said you know enough about programming to be able to add two more variables and figure out how to determine the highest and lowest variables -- just think about it a bit. When you enter a number, test it against the highest value -- if the new number is greater then set the high-counter equal to the current number. Same algorithm for keeping track of the lowest number.

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

how much education do you have already? Have you completed an MS, MA or MBA program? After another 10 years or so full-time experience in the work force you will probably have a good idea what you want to major in the Ph.D. program. Frankly, a Ph.D. isn't worth the effort unless you want to do research or teaching. People with that much education have very limited opportunities in the work force because they are over-qualified for most IT jobs.

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

I would critique one thing...

Typing in all caps, i.e., HIGHLY EXPERIENCED JAVA PROGRAMMER, does two things to your resume'...

1) Typing in caps makes the paper harder to read. We remember where we are in reading by the rise and fall in characters. Typing in all caps eliminates these; I've heard of a study in which reading comprehension scores dropped dramatically when tested with caps.

2) While attempting to emphasize a key point, you are in turn de-emphasizing the rest of that section.


These are merely my opinions... ^.^
Good article though.

3) Using all caps to emphasize anything other than section headings is the same as screaming -- no one likes to be screamed at. Many managers will just toss such a resume in the shredder, never to be seen again.

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

If you really wrote that program then it should not be all that difficult for you to complete the assignment. Just add two more variables to hold the highest and lowest values. If however you did not write that code, then you are committing plagiarism (claiming something is your work when you know it isn't).

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

I saw that yesterday too using IE6. And I saw a couple problems (?) just now on both IE7 and FireFox 2.0.0.1. There is some white space (rectangle) in the upper-left corner where an add probably belongs, and in the lower-right, just beneath "Todays Posts" (no posts listed)

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

Lerner: A couple problems with the code you posted:

>> 1. int numberstrings == 0;

you need to use the assignment operator = instead of boolean operator ==.:mrgreen:

>>5. store_string(char*string)
This is a function prototype, not a function call

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

stick with c++, the parts that are confusing now will eventually become clear to you. Nobody learns all that stuff over night.

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

>>how do i make sure the student id becomes the output file name,
using sprintf() to format the filename string

char filename[80];
sprintf(filename,"%d.txt", sudentID);

>>and that the entered answers are printed into that specific file
using fprintf() function. The second argument is the format string which tells fprintf() about the other arguments. %s tells printf() to print a standard c null-terminated string.

char answer[3] = "a"; // The answer to a question
fprintf(out,"%s\n", answer);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ is NOT a requirement but C (or some other language) is. People have been writing GUI programs for years and years with only C programs. c++ classes will make GUI programming a bit easier, but is not absolutely necessary.

*nix GUI and MS-Windows GUI are completely different, but there are toolkits that make programs portable between the two operating systems.

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

Newlines on some systems are done with \r, \n, or \r\n (I forget which goes with which). Hence, non-portable.

True, but that is handled by the stream implementation. '\n' is interpreted correctly by the stream class. If you check the data that is stored in the file (read the file in binary mode) you will see the conversion:

*nix: '\n'
MS-DOS/MS-Windows: '\r\n'
MAC: '\r'

Ravalon is correct -- using '\n' is completely portable and always has been. The c++ standards did not change that.

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

>>In fact, most of the time you want to flush a stream, it gets flushed for you automatically anyway, and it's redundant to use something that explicitly flushes the stream for you.

That may be true of console screens but probably not of file-based streams. That behavior is os dependent -- when the operating system's buffer(s) get flushed to the file system may not occur until the file is closed or when flush() is called. There are a few rare occasions when a file is intentially left open for long periods of time, and calling flush() occasionally helps reduce the possibility of losing data if the os crashes or keeps the file up-to-date in case another process wants to read it.

But I agree that endl should normally be avoided.

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

please rep quickly

Don't be so impatient --

>>program to plot sign of angles from 0degree to 180 degree with increment of 10 degree
I don't know the answer, but it would depend on the operating sytem and compiler you are using, and whether you want GUI or console program.

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

Your question has been asked before -- please read this thread.

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

why not just have one button and toggle its title between start and stop. Inside the button's event handler get the button's text, if its start change it to stop and do the start function, otherwise if its stop change it to start and do the stop function.

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

you have to add a function or class *.c or *.cpp to the library before the compiler will create the .lib file. Just putting the *.h in the project is not sufficient -- there must be some executable code. And you will find the .lib file in <project name/debug or <project name>/release directory.

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

Is this the Adbrite site? I didn't have any problems with it.

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

why would you want to save folder shortcuts in a database table? When I delete the shortcut or folder it will just make the table obsolete.

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

I'm 64 -- born 1943. Contrary to popular belief, age does not make one wiser -- just makes one older.

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

moved

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

but it's NOT english. Exemplary is an adjective, not a noun. Anamemnis is a noun, not a verb.

People should not try to get cute with the English Language on boards that are read by many peoples around the world -- English is not the native language of many of our posters. And no one expects anyone to be English professors either; expertise in the English language is not a prerequisite for posting here either.