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

see these google links. Make sure whatever you decide to do that the course(s) are accredited. Talk to your school counseler about whether the courses are transferrable or not because many of them are not unless you get the bachelor's degree with that institution.

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

>>for(int i=1; i<(cnt-2); i++)
you don't need that cnt counter. Just delete it

lines 25-30 are reading the file again, not writing to it. Close fin before that loop

fin.close();
fout.open("filename");
for(int i = 0; i < lines.size()-2; i++)
   fout << lines[i] << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
if ( !fout.fail() )
    { // if began
       fout << p->Objperson.nombre << endl; 
       fout << p->Objperson.ss << endl;
       fout << p->Objperson.edad << endl;
    } // if end

That should be a while loop. Also your program will be a little more efficient if you do not use endl because endl does more than print '\n'.

while( p != NULL)
{
       fout << p->Objperson.nombre << '\n'; 
       fout << p->Objperson.ss << '\n';
       fout << p->Objperson.edad << '\n';
    p = p->next; // or whatever pointer you use in that structure
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look at line 13 of the *.cpp file then compare it with line 30 of the header file. The first parameter of the function in the *.cpp file does not match the parameter in the header file.

Also, the cpp file must declare the class name

void Football::SearchMatches(Match* matches,int size,string TeamName)
{

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

There is no difference between structures and c++ classes other than default access. Unions are the same as they are in C -- all members of a union occupy the same memory location.

>>classes and their associated components are instantiated in memory in pretty much random order, but structs and unions are instantiated in a fixed order? Is this true?
I don't know -- never heard of that. Both structure and class objects should be allocated in the order in which they are declared. If allocated dynamically then the memory will be in some memory that is unknown to the program (the memory allocation functions will of course know).

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

maybe you should post that question in the Shell Scripting tech board

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

That sure is an interesting link -- the comments by posters are more interesting than the original blog writer.

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

I made the change suggested. Following is the code. It is not able to delete the first three lines:
I am not able to find what is wrong.

That's because the file was opened for read, therefore writes will fail. You need to use two fstream objects. 1) ifstream to read from the original file, and 2) ofstream to write to a new temporary file. Here is some psudo code.

open input file 
open output file
for each row in the input file
    if counter > 3 then write to the output file
end of while loop
close both files
delete the original file (using remove() function)
rename the temp file to the same filename as the original (use rename() function)

i also wish to delete the last three lines of a file.. should i use c++ program or a unix script

what did your teacher tell you to do. write a c++ program or write a unix script?

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

line 8: you might as well delete it because the compiler will delete it when you compile the program for release mode. Instead of using assert, just test as normal

if( !foud.is_open())
{
    // open failed
}

line 10: don't use eof() like that because it doesn't work that way. Here's the correction

while( getline(fout,temp) )
{
    // blabla
}

line 26: >> /* End of writing to a file */
You have done no such thing!

Ok so now you have read in the file into the linked list. Now you have to add code to rewrite the file.

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

I think the process that creates the shared memory must stay alive until all other processes are done using it. When the creating process dies the os deletes the shared memory. Here is a description for Solaris, which is probably identical to the work I've done with IBM unix.

But, I could be wrong about that too.

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

I never use the else in a statement like that. But there really is nothing wrong with it because a good optimizing compiler will probably delete the else anyway.

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

Those ACM links are probably pretty useless to the OP. Not unless he has a Masters or Ph.D. in computer science or something which I doubt.

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

Sorry, but that is absolute nonsense!

As a freelance journalist myself I can assure you that asking experts for comment/research which is then quoted within the context of a piece, and duly accredited as such, is most certainly not illegal, unethical or anything other than normal working practise.

Agree -- If that were illegal or unethical I don't think there would be any books written that does not contain original thought :)

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

Well, how do we get the questions and how to we respond to them ? If you post the questions here we can either post our answers or sent you PM with the answers. I know DaniWeb normally does not allow answers via PM but this may be a special case because the answers may contain confidential information that should not be publically posted.

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

I tried to upload a *.zip file in this thread (post #28) and it failed. I thought zip files were acceptable.

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

Here are the files I compiled in .zip form. Just use winzip to uncompress them in the directory of your choice.
[edit]DaniWeb will not upload *.zip files, so I changed the filename to *.txt. After you download it, change the file back to *.zip and use winzip on it.[/edit]

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

I did do as you said anyway now. I opened the .cpp and .hpp files in the browser and saved these files as textfiles. The project compiles except for the .ccp file.

That was a huge mistake. When you download the three files you have to click the Save button in the download window, not open it with the browser. From what I see in the text files you posted your browser added a lot of html code to the files that the c++ compiler doesn't know how to handle.

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

I download all three files and successfully compiled with with VC++ 2008 Express after making a couple changes.

  • name a.cc to a.cpp
  • have to add #include <limits> to each of the two *.cpp files
  • VC++ 2008 Express does not recognize and and or, so add these macros after the includes in each *.cpp file
    #ifndef or
    #define or ||
    #endif
    #ifndef and
    #define and &&
    #endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the datafile.cpp that I get with the link posted by Duoas in post #17. As you see stdafx.h is not included here. I deleted most of the code to show only relevent parts. If there is a more recent copy then you should post it. Those text files you have posted are worthless because they are unreadable. Post the *.cpp file.

// datefile.cpp
// Copyright (c) 2008 Michael Thomas Greer.
//
// Boost Software License - Version 1.0 - August 17th, 2003
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your project is using precompiled headers so the first line after the comments at the top of the *.cpp file must contain #include "stdafx.h" . If it doesn't eppear on the first line, add it.

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

How exactly does the code you posted attempt to solve the problem ? Answer: it doesn't -- the code is for a completly different homework problem.

Do the requirements one at a time. Your first task is to create a structure that contains three items: last name, first name, and id. After that write a program with a loop that lets you enter each of those items and add a new structure object to an array of structures.

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

>>if( (s_current.compare(struct_filedata.name) && s_parrent.compare(struct_filedata.name)) )

use || operator instead of && because it can't be both at the same time.

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

you must have something else wrong because your function compiled ok for me. All I did was make it a simple function and declare the vector globally.

#include <iostream>
#include <string>
#include <io.h>
#include <vector>
using namespace std;

vector<string> m_vFilenames;
int MakeList(string p_sPath)
{
	cout << "Parameter: " << p_sPath << endl;
	struct _finddatai64_t struct_filedata;
	string s_filename = p_sPath + "\\*.*";
	string s_current = ".";
	string s_parrent = "..";
	
	cout << "Listing " << s_filename << endl;

	long nHandle = _findfirsti64(s_filename.c_str(), &struct_filedata);
	if(nHandle >= 0)
	{
		while(_findnexti64(nHandle, &struct_filedata) == 0)
		{
			if(struct_filedata.attrib & _A_SUBDIR)
			{
				if( (s_current.compare(struct_filedata.name) && s_parrent.compare(struct_filedata.name)) )
				{
					s_filename = p_sPath + "\\" + struct_filedata.name;
					cout << "Subdir found: " << s_filename << endl;
					MakeList(s_filename);
				}
				else
				{
					cout << "Dir found: "  << struct_filedata.name << endl;
				}
			}
			else
			{
				cout << "File found: " << struct_filedata.name << endl;
				m_vFilenames.push_back(struct_filedata.name);
			}
			
		}
	}
	else
	{
		cout << "Path not found." << endl;
		return -1;
	}


	return 1;
}

int main()
{

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

>> Where does WinAPI fit into all this
That is the Windows operating system functions. OpenGL, DirectX, etc are wrappers around win32 api functions. You can do windows graphics without OpenGL or DirectX, but you can't do OpenGL without the WinAPI.

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

We have cameras at work too but I normally ignore them, just do my job. The cameras are there for customer theft, and they do work/record all the time.

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

I believe both -- God created everything, how he did it was through evolution.

jephthah commented: makes the most sense to me. just don't tell richard dawkins :P +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If this is the original function

int foo(int x)
{
    while(x < 10)
      x = x + 1;
   return x;
}

Then you can do this:

int foo(int x)
{
    if(x < 10)
    {
        x = x + 1;
       foo(x);
    }
    return x;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int try(int *add)
{
	if(add()>10)
           try(sub);
}

That does work because the parameter to try() is not a pointer to a function. This should fix the compile error.

int try(int (*fn)() )
{
	if(add()>10)
           try(sub);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>@ AD: can u please post the source code and the file u compiled on here ? I use dev-c++ too and doesnt work ><
I used exactly the same source code that appears in post #7 in this thread, except I fixed the void main. I didn't use a data file so it didn't actually read anything. But the program didn't crash as niek_e suspected.

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

line 155: >> matches[matchesCounter].Season

matches is an array of unallocated pointers, so you have to use the pointer operator, like this: matches[matchesCounter]->Season Before you can do the above you have to allocate memory for the structures. Here's how:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		getline(inFile,Buffer);
		matches[matchesCounter]->Season = Buffer;
		//read team1 name
		getline(inFile,Buffer);
		matches[matchesCounter]->Team1 = Buffer;
		//read the "over" string
		getline(inFile,Buffer);
		//read team2 name
		getline(inFile,Buffer);
		matches[matchesCounter]->Team2 = Buffer;
		//read result
		getline(inFile,Buffer);
		matches[matchesCounter]->Result = Buffer;
		//read the empty line
		getline(inFile,Buffer);
		//update the matches counter
		matchesCounter++;
	}

you can simplify like this:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		getline(inFile,matches[matchesCounter]->Season);
		//read team1 name
		getline(inFile,matches[matchesCounter]->Team1);
		//read the "over" string
		getline(inFile,Buffer);
		//read team2 name
		getline(inFile,matches[matchesCounter]->Team2);
		//read result
		getline(inFile,matches[matchesCounter]->Result);
		//read the empty line
		getline(inFile,Buffer);
		//update the matches counter
		matchesCounter++;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just compiled and ran your program in Dev-C++ and the window didn't close on me. I also ran it from command prompt and it worked there too.

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

you have to put a line at the end of main() to keep the window from closeing. Add a getchar() will do it.

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

If you have a lot of classes that can be used in several different projects then put the classes in a library or DLL. That way you only have to complie the classes once. Then you tell the compiler to link the application program, that includes main(), with the library. One way to do that is use the #pragma directive

// main.cpp
#include <string>
// other includes here

// force the compiler to link with your library
#pragma comment(lib,"mylib.lib")

>> If for instance u have 20 classes, u write all the code(classes) in the same environment, that in the same cpp file???

No. Each class can be in its own *.cpp file, and all the *.cpp files can be in the same project. A project can contain as many *.cpp files as you want. And in Visual Studio projects and contain other projects.

Traicey commented: U see what I was telling u +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Go to menu Tools --> Editor options, then select the General Tab. In the lower right-hand side is where you set the tab size. But you may also have to turn off Smart Tabs

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

Instead of using the loops to initialize the array, you can also do it when the array is declared, like this: float a[M][M] = {0}; The above will initialize all elements of the array to 0.

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

you opened the file for reading, not writeing.

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

but i still want to be able to use string uri50?!!

What I posted doesn't prevent you from doing that. All it does is provide a "" value when the calling function omits that parameter.

Line 56 would then become: ipuri.ip_uri(ip50);

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

you can give it a default parameter of a blank string
line 12: string ip_uri(string ip50, string uri50 = "");

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

Don't expect any mod to answer questions via PM -- we don't. Post all questions on one of the DaniWeb boards.

And I moved this thread to a more appropriate board.

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

Don't be afraid to make liberal use of { and } braces. And pay attention to spacing. Both these will help you greatly in understanding the logic of your program.

if ( Size < MAX_SIZE )
{
    Data[ Size++ ] = NewData;
}
else
{	
    // Only the five recentmost numbers are subject to testing
    // so, drop the first and pushback the rest, and insert
    // newest element into spot five.
    for ( Index = 0 ; Index < MAX_SIZE - 1 ; ++Index ) 
   {
               Data[ Index ] = Data[ Index + 1 ];
   }
   Data[ MAX_SIZE - 1 ] = NewData;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well you can write empty functions for now and implenent/test them one at a time. Don't try to code them all at one time or you will just get overwhelmed by all the compiler errors that you will get. As another DaniWeb member said (I don't recall who), use the Divide And Conquor method. Do one function at a time and soon you will have the program complete.

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

va_args will be of no help to you because all it does is point to the beginning byte of the stack where a variable of unknown size starts. The program still has to know the data type.

This is how I impleneted a general-purpose linked list

typesed struct node
{
    void * data; // data for this node
    struct node* next;
    struct node* prev;
} LINK;

To insert a node at the head of the linked list.

struct node* insertHead(LINK** head, void* data)
{
      LINK* newNode = malloc(sizeof(LINK));
      newNode->data = data;
      newNode->next = NULL;
      newNode->prev = NULL;
      if( *head == NULL)
           *head = newNode;
     else
     {
         newNode->next = *head;
         *head = newNode;
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Will this do the job?
Don't know -- why don't you compile and test it to see if it will work correctly. add a print statement on every insertion to see if the array was shifted correctly.

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

Here is how to extract all email addresses on a single line. It just keeps find the @ symbol until no more can be found. Once the @ symbol is found this program erases the address from the line and looks again for another @ symbol.

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

int main()
{
    // list of all valid email characters.
    string chrs = "-_.abcdefghijklmnopqrstuvwxyz123456890";
    // a line that contains two email addresses and some other stuff
    // Assume the emails below are fake -- I don't know if they are real or not.
    string line = " here at cscgal@daniweb.com and here too happygeek@daniweb.com";
    size_t pos = 0;

    while( (pos = line.find('@') ) != string::npos)
    {
        string st = line.substr(0,pos);
        line = line.substr(pos);
        for(size_t e = st.length()-1; e >= 0; e--)
        {
            char c = st[e];
            if( chrs.find_first_of(c) == string::npos )
            {
                st = st.substr(e+1);
                break;
            }
        }
        if( (pos = line.find(' ')) != string::npos)
        {
            st = st + line.substr(0,pos-1);
            line = line.substr(pos+1);
        }
        else
        {
            // end of line found, so just empty the string
            st += line;
            line = "";
        }
        // print the email address
        cout << st << "\n";

    }

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

that first, outside loop is wrong.

string lineFromFile;
while( getline(fin, lineFromFile) )
{

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

puts() adds the '\n' to the end of the string. call printf() instead printf("SHELL>"); >>In the past time, i've been used terminal libraries like the infamous conio.h in turboc
That is what you get for learning ancient and obsolete version of C compilers. They teach you very bad habits that are sometimes difficult to unlearn.

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

>>ifstream ReadFile("C:\\File1.txt");
That is text mode. Here is binary mode: ifstream ReadFile("C:\\File1.txt", ios::binary);

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

yes, ODBC is one way, and is supported by most, if not all, modern SQL compliant data bases. There are already several free odbc c++ classes. So what you are trying to do has already been done several times in the past 10 or so years.

For MySql specifically, you can download free MySQL++.

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

>>Thank you. I will look the seekg() method up in msdn.
You might find it there, but that is a standard c++ fstream function. Look here instead.

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

By anime, do you mean animated ? If yes, the last one I watch and enjoyed was Ratatouille