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

Post your text file -- that worked ok for me using vc++ 2008 express.

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

sizeof( any pointer ) is always the same -- sizeof returns the number of bytes it takes to store the address of the pointer, not the length of the string the pointer references. So lines 12 and 13 of your code will always return the same value (probably 4).

line 14: you are attempting to store an unitialized pointer into the vector. undef points to just some random memory location, and that may cause a seg fault, especially if you later attempt to do anything with that pointer.

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

Is there a question somewhere?

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

See this related thread.. If the file really is not in the directory you posted then you might need to reinstall the .NET framework.

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

Pretty simple, really

bool Class_name::find_a_record(ifstream& is, string name)
{
     Class_name n;
     is.seekg(0, ios::begin); // start at beginning of the file
     // while not end-of-file or error
     while( is.read( (char*)&n, sizeof(Class_name) )
     {
            if( name == n.name) // if found
            {
                  return true;
            }
     }
     return false;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to get a list of all the files in the folder ( see FindFirst() and FindNext() win32 api functions). Then for each of those call _stat() to get the file creation date and compare that with today's date. Finally, use remove() to delete the file.

Where should it be written: In the com component's startup code, probably in main(). If the com program is a windows service then you might want to put the code in another thread so that it can be put to sleep for 24 hours before running it again. This would assume the com component will stay in memory for a long long time, i.e. several days.

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

Here is how to get a list of the drive letters

#include <windows.h>
#include <iostream>


int main()
{
    char buf[255];
    char cDrive;
    // get the drive letters as a set of strings
    int sz = GetLogicalDriveStrings(sizeof(buf), buf);
    if( sz > 0)
    {
        // buf now contains a list of all the drive letters.  Each drive letter is
        // terminated with '\0' and the last one is terminated by two consecutive '\0' bytes.
        char* p1 = buf;
        char* p2;
        while( *p1 != '\0' && (p2 = strchr(p1,'\0')) != NULL )
        {
            std::cout << p1 << "\n";
            p1 = p2+1;
        }
    }
    else
    {
        // Oops! something went wrong so display the error message
        DWORD dwError = GetLastError();
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError, 0, buf, sizeof(buf), 0);
        std::cout << buf << "\n";

    }
}

For the files that are in the drives you need to use FindFirstFile() and FindNextFile(). Google and you will find examples.

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

depends on the operating system.

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

I assume you did not post all the code in those two function. If you are getting just some random values then you are probably using some uninitialized variables in those function. Post the entire program so that we can see what you are doing.

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

try this

In c++ I would use either <vector> or <list> c++ classes instead of creating your own linked list as you might do in C language.

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

line 32 is a string in scientific notation. The value is just too small to be represented in normal double precision, so you have to display it in scientific notation, like this: printf("%e\n", array[n]); // Here it doesnot In the value 2.657374814e-012 the -012 tells you to move the decimal point 12 places to the left, which makes the number 0.00000000000265..., a very very tiny number.

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

>>well besides printing 1 to the display..

The reason for that should be obvious.

Also compiled with Code::Blocks using MinGW (gcc 3.4.5) and it worked ok.

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

Worked fine for me using vc++ 2008 express

ans->1
enter a value/guess->1234
found it!
Press any key to continue . . .

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

>>while ((addr = ((void*(*)(void))addr)())

Didn't your compiler produce an error or warning on that line?? tryit() does not return a value, yet in the above addr is being assigned the return value of tryint(). You can't have it both ways. try this: while( addr() )

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

line 61 in the code you posted: That function displays random/wrong values because it is using uninitialized variables.

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

It returns gibberish because when that NextTag() returns the array radial is destroyed, which invalidates tags[1]. What you need to do is allocate memory for the text. Then main() will have to delete[] that memory when its done with it.

tags[1] = new char[strlen(radia1)+1];
strcpy(tags[1], radia1);

Another way to do it is for main() to allocate memory for that string

char* tags[4] = {0};
char radia1[80];
tags[1] = radia1;
...
...
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

variable ptrA needs to have three stars

#define maxrows  2
#define maxcols 5


int main()
{
	double a[maxrows][maxcols];
	double ***ptrA = malloc(maxrows * sizeof(double*));
	int i,j;

	for(i = 0; i < maxrows; i++)
	{
		ptrA[i] = malloc(maxcols * sizeof(double*));
		for(j = 0; j < maxcols; j++)
		{
			ptrA[i][j] = &a[i][j];
		}
	}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are going to do this kind of advanced-level programming then you really need to learn how to debug your own errors. The problem is those two defines on lines 552 and 553. Delete them.

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

If you want the 2d vector to contains either strings or ints, then maybe you need to create a template class.

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

The parameter to open() has to be a null-terminated character array (commonly called a string). All you are trying to send it is a single character. Try this:

int main()
{
int i;
char* letras[3] = {"a","b","c"};

for(i=0;i<3;i++)
{
    ofstream print(letras[i]);
}

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

The only one right decidion is to overload the operator<< () and operator>> ()

Yes, that is another way to do it, but not the only way. Overloading the operators would take more processing time because the program would have to read/write the structures/classes one at a time. The way he is doing it the entire array is read/written all in one shot.

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

>>.btw,isnt there (char*)&B?
NO. B is already a pointer, so what you would create is a pointer to a pointer.

You didn't post the entire program so I can't help you more. I have no clue what Option 2 (or any other option) is.

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

Windows 7 itself contains a program that resizes the partition. If you can install Windows 7 then go to Control Panel --> System and Security --> Administrative Tools --> Computer Management --> Storage --> Disk Management Then right-click on the partition you want to shrink and click Shrink Volume. At that point I'm not certain if it was expand the c: primary partition or create yet another partition.

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

line 48: it is not reading the value of n from the data file. You need to put f >> n; between lines 47 and 48.


delete line 49 because that's the default when files are opened for reading.

line 50 should be this: file.read((char*)B,sizeof(books)); . The value of i is probably outside the bounds of the array anyway at that point.


line 51 is wrong. use < operator, not the <= operator.

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

make the function averate() return the average so that main() can determine whether it is pass or fail.

int average(int n)
{
   ...
   ... <snip>
   return sum/num;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read the file one word at a time, instead of one charcter at a time. If the word contains digits then convert the entire word to int so that "10" becomed 10. line 10 should be an array of ints, not an array of char, so that it can contain ints beyond the range normally occupied by a single char.

godsgift2dagame commented: Hey AC, thanks a lot for your help! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of tutorials on the net, here's just one of them.

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

Can you use arrays? You don't have to,

Since the average has to be done in a separate function I don't see any other way to do it but use an array. The number of scores is unknown until runtime so its not possible to just declare a bunch of integers.

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

you will need to declare an array of ints that hold the individual test scores so that they can be averaged later. Then pass that array to the function to computes the average. Declare and allocate the array between lines 11 and 12 of the code you posted. int* arry = new int[numValues]; Then delete line 15, and change line 16 to cin >> arry[count];

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

line 12: its int main().

The rest is just too difficult to read because of terrible formatting. Don't be afraid to use some spaces to indent lines.

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

>>so it's potentially got multiple leading zeroes, which will be lost in the conversion process from int to string to int.

What's the problem with that? Integers never contain leading zeros, whether the strings have them or not.

What I would do is convert the three integers into seconds so that they can be easily compared with current time. int totalSeconds = hours * 60 * 60 + minutes* 60 + seconds; Now get a struct* tm for current and make the same calculation.

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

>>just move my code cpp code into my .h file.
You don't read very well, do you? The answer is NO NO NO.

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

line 9, my_vector.h NEVER EVER include a *.cpp file in a header file. It doesn't work. You didn't say what compiler you are using but you have to compile all *.cpp files and then link the object files together to make a single executable program.

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

how do i use a print statement for arrays?

something like this:

int array[10];
int i;
for(i = 0; i < 10; i++)
{
    printf("%d\n", array[i]);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can do this

class test 
{
public:
    std::string write();
};
 
std::string test::write()
{
	std::string name = "HELLO";
	return name;
}


int main ()
{
	  test A;
	  cout << A.write() << endl;
	  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>However the array dosent show
What does that mean? And please use code tags.

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

>>if (the number is a character) //don't quit get that

You will need to get the number in a char variable, not an int variable. Then the above line will make sense because you need if( !isdigit(character)) maybe this will make more sense

#include <iostream>
using namespace std;

int foo()
{
	char c;
	cout << "Enter a character\n";
	cin.get(c);
	if( !isdigit(c) )
		throw "Not a digit";
	return c;

}

int main()
{
	char c = 0;
	try
	{
		c = foo();
	}
	catch(const char* msg)
	{
		cout << msg << "\n";
	}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My bet is that the window is closing before you have a chance to see the output. The reason is that when you enter numeric data the program will leave the Enter key '\n' in the keyboard buffer, and when cin.get() is called it just retrieves it. When you need to do is flush that out of the buffer. Add cin.ignore(); after cin >> width; [edit] What ^^^ Tom said :) [/edit]

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

Use a friend function to overload the >> operator

class Time
{
private:
    int hour, minute, second;
public:
    Time() {hour = mijnute = second = 0;}
    friend istream& operator >> (istream& in, Time& t);
};

// Put this in the *.cpp file, not the *.h file
istream& operator >> (istream& in, Time& t)
{
           cout << "Enter time";
           cin >> t.hour >> t.minute >> t.second;
           return in;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It depends on the program you write. You might read through this rather old thread to see if it gives you any ideas.

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

>>when I compile, there are no errors,
Ditch the compiler and use a different one. There is a link error.

>>void print ()

Wrong. should be void testClass::print ()

Gem74 commented: It worked! error solved! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need two loops to do that. You have to check each number against all the previous values.

int a[10] = {5,6,7,8,9,10.11,12,13,1};
int i,j,isTrue;
isTrue = 1; // assume true
for(i = 0; i < 9 && isTrue == 1; i++)
{
    for( j = i+1; j < 10; j++)
   {
       if( a[i] > a[j] )
       {
             isTrue = 0;
             break;
      }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 41: That is a horrible way to test for eof -- all you need is this:

while( getline(inputFile, line) )
{
    cout << line << '\n';
}

lines 55-60: WTF??? You can not code nested while loops like that and expect anything other than the results you got.

while( inputFile >> name >> a >> age >> number)
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 74-80: you don't need to call strcmp() to compare two std::string objects -- just use their == operators if(type == normal) Recode lines 98-105 similarily.


Also those if statements will give you a false validity result. Lets say the type is gold. The very first if statement about normal will set valid to false, which is incorrect. The way to do it is to have just one if statement that tests all of them at the same time

if( type != normal && type != silver && type != gold && type != plat)
    valid = false;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void foo(const char* str)
{
   // display the string contents here
}

int main()
{
   foo("Once upon a time ...");
   foo("there were three little pigs.");
   // etc etc
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

make a function out of that code then send the strings to it.

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

if you mean char yes; then just delete them.

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

put a system pause between letters. Assuming you are coding on MS-Windows.

#include <windows.h>
...
...
string msg = "This is a test";
for(int i = 0; i < msg.length(); i++)
{
    cout << msg[i]; cout.flush();
    sleep(1000); // delay 1 second
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete line 40 because it is hiding the declaration in the class itself.