Tom Gunn 1,164 Practically a Master Poster

But that means I still have to retain my original code where I have it under:
private void btnCount_Click(object sender, EventArgs e)
is that right?

If you still want to have the same behavior on a button click that you do now, yes. But keeping a running count means you do not need to have a separate button that counts all vowels from scratch.

Btw, if I write the private int _vowels = 0; I got an error saying that expected token. What does it mean?

You may be adding it to the wrong place. _vowels is a field for your form class, not a local variable. The code I gave has it in the right place. Make sure that you do the same thing and it should work.

Tom Gunn 1,164 Practically a Master Poster

The event is fired for each character. You do not need to loop over everything that has already been tested in the text box. Test just that one character and add to a count field:

public class Form1
{
    private int _vowels = 0;

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        // you write IsVowel()
        if (IsVowel(e.KeyData)) ++_vowels;
        else
        {
            // handle backspacing and deleting if you want
        }

        labelCount.Text = _vowels.ToString();
    }
}
Tom Gunn 1,164 Practically a Master Poster

Please do not roll your own encryption code. It's fine for a homework exercise but anyone who uses that kind of thing in a real application needs to be shot. ;) At the very least, if you do not care about how strong the encryption is, use the libraries offered by the the framework:

using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace Daniweb {
    public sealed class Encryption
    {
        // use an 8 byte key for DES encryption
        private static byte[] _key = new byte[]
        { 
            0xBA, 0x87, 0x09, 0xDC, 0xFE, 0x65, 0x43, 0x21 
        };

        private static byte[] _IV = new byte[]
        { 
            0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF 
        };

        private Encryption() {}

        public static string Decrypt(string data)
        {
            byte[] input = Convert.FromBase64String(data);
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(
                ms,
                des.CreateDecryptor(Encryption._key, Encryption._IV),
                CryptoStreamMode.Write);

            cs.Write(input, 0, input.Length);
            cs.FlushFinalBlock();

            return Encoding.UTF8.GetString(ms.ToArray());
        }

        public static string Encrypt(string data)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();

            // convert input to byte array
            byte[] input = Encoding.UTF8.GetBytes(data);

            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(
                ms,
                des.CreateEncryptor(Encryption._key, Encryption._IV),
                CryptoStreamMode.Write );

            cs.Write(input, 0, input.Length);
            cs.FlushFinalBlock();

            return Convert.ToBase64String(ms.ToArray());
        }
    }
}
Tom Gunn 1,164 Practically a Master Poster

You can do it with the KeyPress or KeyDown event for the text box. Both of those have event args that tell you what key was pressed.

Tom Gunn 1,164 Practically a Master Poster

Show the login form first, then if the login is successful, open the MDI form from the login form:

void buttonLogin_Click(object sender, EventArgs e)
{
    string user = textBoxUser.Text;
    string pass = textBoxPass.Text;

    if (IsValid(user, pass))
    {
        new MainForm().Show();
        Hide();
    }
    else
    {
        MessageBox.Show("Invalid user name or password");
    }
}

But do not forget that the login form is still the controlling form for the application. If you exit the main form, it will not close the application because the main for is not the controlling form. In the main form, add a handler for the FormClosed event that will close the application:

void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    Application.Exit();
}
Tom Gunn 1,164 Practically a Master Poster

I need to display
Example
23.4
and display 23 and .4

One easy way is with the type system. When you cast a floating point value it cuts off the precision. If you subtract that result from the original, you get the precision:

double d = 23.4;
double w = (int)d; /* w == 23.0 */
double p = d - w; /* p == 0.4 */
Tom Gunn 1,164 Practically a Master Poster

Is it because my float values are too big?

Or too small. Or too precise for fixed notation. You can print the usual way with the fixed manipulator.

#include <iostream>

using namespace std;

int main()
{
    double d = -4.49255e+013;

    cout << fixed << d << '\n';
}

But if you get values like that and do not expect them, your math might be wrong or you forgot to initialize a variable somewhere. Very large or very small values can sometimes mean an uninitialized variable.

This is required reading for anyone who has questions about floating point. You do not have to be an expert at it and understand everything, but reading it through one time will help.

Tom Gunn 1,164 Practically a Master Poster

Good OO design is like good code. You know it when you see it, but it is not something that can be taught. There are guidelines to get started, but the real teacher is experience with what works and what does not.

Tom Gunn 1,164 Practically a Master Poster

I am not using any features of .NET as I know of. So, why does Visual Studio always ask me to target a Framework in my project.

Make sure you do not have the /clr switch anywhere in your compiler command line options. C++/CLI compiles native C++ to a CLR assembly, so you might be targeting .NET without knowing it. I think /clr is a default switch for empty projects, if that is how you started.

Creator07 commented: Thanks buddy +1
Tom Gunn 1,164 Practically a Master Poster

I still need to figure out if there are other options.

There are other options, but not for two unsorted strings. Most intersection algorithms assume that both sets are sorted and use an algorithm that is both fast and uses little or no extra memory.

Tom Gunn 1,164 Practically a Master Poster

If the two strings are not sorted, the 'best' way depends on what trade off you want to make. If you want to have a small memory footprint but slower algorithm your way is fine. If you want to have a faster algorithm at the cost of more memory, two histogram tables is a good way:

define sa as array[0..CHAR_MAX] = {0}
define sb as array[0..CHAR_MAX] = {0}

// build the histograms
for x = 0 to a.length
    ++sa[a[x]]
loop

for x = 0 to b.length
    ++sb[b[x]]
loop

// print the unique intersection
for x = 0 to CHAR_MAX
    if sa[x] <> 0 and sb[x] <> 0 then
        print x as char
    end if
loop

In C that comes out to about a 10 line function and it has O(n) time complexity.

Tom Gunn 1,164 Practically a Master Poster

How could I modify this so that when I edit a file and save it, it won't have to go through about renaming it and saving it again as if it is a new file?

Most files are too variable to edit in place. Here are some guidelines for working with files:

  • Updating Records: Unless the file has a strict format where the starting address of each record can be calculated, the only way to change records is to rewrite the whole file. Otherwise the starting address can be calculated and then just the one record can be overwritten by seeking to that address.
  • Appending Records: This can be done without rewriting the whole file by seeking to the end or opening in append mode.
  • Inserting Records: This can not be done without rewriting everything in the file past the point of insertion, regardless of format. Just like an array, if you do not make room for the new record, another record will be erased.

    If the order of records does not matter, and the format is strict enough to calculate the starting address, you can save the record that would be erased, overwrite it, and then append it. This will usually be faster than rewriting everything past the point of insertion.

  • Deleting Records: If the format allows deleted or empty records and the starting address of each record can be calculated you can overwrite the record with a null record, otherwise this cannot be done without rewriting everything …
Tom Gunn 1,164 Practically a Master Poster

There are about 10 of this type of "shared" property that I have been quite annoyingly copying into the Scan object each time one is created.

If Scan has a pointer to the Scanner parent, why make a copy of the properties at all? You can access them through the parent pointer at only the cost of an extra level of indirection.

Tom Gunn 1,164 Practically a Master Poster

Now I want to call the thrd party dll written in C in same way. I have just a dll but do not have method name. How can I find the method name from dll? Do I need to have header file to call the dll? What info I need to ask from the third party dll provider? Please clarify on this.

You need to know the method name however the DLL is accessed.

If the provider only gives you a DLL, you can look into the file and find out what names are in the export table, or you can ask the provider what names are exported and how to use them. The second way is easier if you do not know anything about the Portable Executable file format. ;) The provider should at least give you documentation along with the DLL.

To make using a DLL easier, providers can package it with a .lib and .h file. Using the DLL with those two is just like using a static library. You link to the .lib file, include the .h file, and put the DLL in the output directory. The .h file will tell you what names are exported.

Tom Gunn 1,164 Practically a Master Poster

Error Sample1.c : Unable to open include file 'stdio.h'

stdio.h is a header that comes with the compiler. Either the configuration for the compiler is wrong, or the installation is corrupted if it cannot find a standard header file. Have you been able to compile and run programs with this installation of Turbo C before?

Tom Gunn 1,164 Practically a Master Poster

Perfect, thank you. :)

Tom Gunn 1,164 Practically a Master Poster

Is there way to search the code snippets?

Tom Gunn 1,164 Practically a Master Poster

There is not a portable way to set a window title. The best you can do is have something like a appsys.h header with all of the non portable stuff:

#ifndef APPSYS_H
#define APPSYS_H

bool ChangeConsoleTitle(const char *title);

#endif
#include <windows.h>
#include "appsys.h"

bool ChangeConsoleTitle(const char *title)
{
    // windows API
    return SetConsoleTitle(title);
}

This separates the non portable code from the portable code. In the portable code, call ChangeConsoleTitle and when porting to a new system, just change the definition of ChangeConsoleTitle.

Tom Gunn 1,164 Practically a Master Poster

Is this array initialization static or dynamic?

C++ does not allow an array with a size that is not constant. If your compiler compiles that declaration and it runs, then the documentation will tell you how it works. I assume it has the same behavior as an array created with alloca(). alloca() is not a standard C++ function, by the way. ;)

Tom Gunn 1,164 Practically a Master Poster

Why do you want an array? The string class will work for both sides of the encryption:

int main()
{
    string word, dword;

    // read a word

    for (string::size_type x = 0; x < word.length(); ++x)
    {
        dword += Crypt(word);
    }

    cout << word << '\n' << dword << '\n';
}
Tom Gunn 1,164 Practically a Master Poster

Start by loading the DLL with the LoadLibrary function. Then if the name you want is in the DLL's export table, you can call GetProcAddress to get a handle to it. Here is an example program that does everything.

Tom Gunn 1,164 Practically a Master Poster

That would happen if you do this:

C:\> tcc Sample1.c
C:\> tcc Sample2.c

The linker errors because those two calls to tcc are separate. They both try to compile and link the file, but there is no definition of f1 when compiling and linking just Sample2.c. To get the definition, you need to be able to link Sample1.c to Sample2.c. To do both at once and link them together, you do it with one call:

C:\> tcc Sample1.c Sample2.c

Or you compile the Sample1.c to an object file and link it with the object file of Sample2.c, but it is not as convenient as doing it all in one line:

C:\> tcc -c Sample1.c
C:\> tcc Sample2.c Sample1.obj

or

C:\> tcc -c Sample1.c
C:\> tcc -c Sample2.c
C:\> tcc Sample1.obj Sample2.obj

Please excuse any mistakes, I am going on memory of Turbo C. ;)

Before someone else attacks you about your choice of compiler, Turbo C/C++ is very old. There are better options now, like Code::Blocks or Visual C++ Express. Newer compilers make better use of recent improvements in CPUs and compiler design, and your code can only benefit from those improvements. :)

Also, if you want to move from C to C++, a compiler released after 1998 is a must because that is when C++ was standardized. If you use Turbo C++, you will miss out on most of the best stuff from standard C++.

jephthah commented: attack thwarted +14
Tom Gunn 1,164 Practically a Master Poster

That is what I gathered from your question. But as long as you have a Scanner, any factory method can pass a pointer to it as the argument for a Scan constructor call.

Tom Gunn 1,164 Practically a Master Poster

Flip your first thought around. If Scan has a pointer to a Scanner, the constructor can take an argument of this from the Scanner object generating the Scan object:

class Scanner;

class Scan
{
    Scanner *_scanner;
public:
    Scan(Scanner *scanner): _scanner(scanner) {}
};

class Scanner
{
public:
    Scan GenerateScan()
    {
        return Scan(this);
    }
};
Tom Gunn 1,164 Practically a Master Poster

Distance between the two strings? Do you mean the Levenshtein distance or something else?

Tom Gunn 1,164 Practically a Master Poster

NRU is a caching algorithm based on time. Cache some data and when the data is used set a flag bit. At regular intervals, check the flag bits and deallocate the memory for any of the data where the bit is not set. NRU means not recently used inside the time interval.

The code can be as simple as this:

const THRESHOLD = [I]{some seconds}[/I]

let start = time()

while true do
    // do stuff
    // load data into cache if not there
    // set flag bit when cache data is used

    if diff(time(), start) >= THRESHOLD then
        for x = 0 to sz
            if isset(cache[x].flag) then
                release(cache[x])
                remove(cache[x])
            end if
        loop
    end if
loop
tux4life commented: I don't know how you keep doing it, but your replies are always excellent :) +17
Tom Gunn 1,164 Practically a Master Poster

I didn't even know HTML when I was 16. Good job. :)

Tom Gunn 1,164 Practically a Master Poster

I guess this is homework, but if it is not, the library already has this stuff:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <string>

using namespace std;

// use basic_string<T> to allow any char type
template <class T>
basic_string<T> Intersection(
                             const basic_string<T>& a, 
                             const basic_string<T>& b)
{
    set<T> sa(a.begin(), a.end());
    set<T> sb(b.begin(), b.end());
    basic_string<T> c;

    set_intersection(
        sa.begin(), sa.end(), 
        sb.begin(), sb.end(), 
        back_inserter(c));

    return c;
}

int main()
{
    string a = "abcdefgerbcad";
    string b = "qwbebczdelkn";

    cout << Intersection(a, b) << '\n';
}

If it is homework, I am not allowed to give you any code, but there is a simple algorithm with two histogram arrays. The first array is a histogram of the characters in the first string out of all characters. The second array is a histogram of the second string. Loop over both arrays and print every character that has a value greater than 0 to find the intersection.

Tom Gunn 1,164 Practically a Master Poster

I have a function under Base class and at the definition tine of this base class function I need to call another function which is define under the Derived class. how to do this??

Make the method virtual and protected in the base class, then override it as public in the derived class:

class Base
{
public:
    void showdata(double a)
    {
        cout<<"The value of the Function : " << F(a);
    }
protected:
    virtual double F(double) { return 0; }
};

class Derived: public Base
{
public:
    double F(double x)
    {
        return exp(-x) + x*x;
    }
};

That solves the problem of a base class needing to call a derived class method, but your example does not show why you need that behavior. What are you trying to do?

Tom Gunn 1,164 Practically a Master Poster

I see where you're going. Should I be flattered that you think I am this guy who stopped posting at the same time I joined?

Tom Gunn 1,164 Practically a Master Poster

First I get attacked for not being perfect right out of the gate. Now I get attacked for fitting in. What do you want from me? :confused:

Tom Gunn 1,164 Practically a Master Poster

I'm using Windows XP and I did check my Processes and I saw where most of my memory was going, but I think I need to upgrade my memory it's only 256 mb of Ram.

I recommend an absolute minimum of 512MB for Windows XP, and at least 1GB for good performance on anything more than surfing the internet. ;)

Tom Gunn 1,164 Practically a Master Poster

I don't think you have spoken anything in that regard.

I have not bothered to seriously answer this question because it is too ambiguous. Each time thr clarifies what he wants, I get more confused. Now X is an abstract class. I can suggest something like this:

#include <iostream>

using namespace std;

class X
{
	public:
		virtual void function( ) = 0;
	protected:
        X(int xx, int yy): x(xx), y(yy) {}
		int x,y;
};

class Y: public X
{
public:
    Y(int xx, int yy): X(xx, yy) {}
    void function() { cout << x << ',' << y << '\n'; }
};

int main()
{
    X *arr[10][10];

    for (int x = 0; x < 10; ++x)
    {
        for (int y = 0; y < 10; ++y)
        {
            arr[x][y] = new Y(x, y);
        }
    }

    for (int x = 0; x < 10; ++x)
    {
        for (int y = 0; y < 10; ++y)
        {
            arr[x][y]->function();
            delete arr[x][y];
            arr[x][y] = 0;
        }
    }
}

But it is just a shot in the dark.

Tom Gunn 1,164 Practically a Master Poster

Is there ANY standards compliant way to get unbuffered input from the console without the characters being automatically displayed?

Short answer, no. The console does its own buffering, and then C++ does another level of buffering for performance. You can change C++'s buffering, but that only affects performance. By the time your program gets the characters, they have already been displayed on the console.

The only way to change the console's buffering is with a system level API, and that is not portable. That is what getch() does, but the standard does not define a function with getch()'s behavior.

Tom Gunn 1,164 Practically a Master Poster

3) wrong, you only create a pointer of type char, this can't hold a string.

The next line assigns the pointer to a string constant:

char *abc;
abc="xyz";

There is no problem here, and the string is read only. It is the same to initializing directly:

char *abc = "xyz";

In fact, the compiler will probably reduce both ways to the same machine code.

tux4life commented: Thanks for the correction :) +16
Tom Gunn 1,164 Practically a Master Poster

What is problem with memory occurs here?because the code will run fine>

It is called a memory or resource leak. The memory you allocated from the first call to malloc is never freed, and for the rest of the program it will stay allocated and cannot be used anymore because you do not have a pointer to it.

The problem is that memory is finite, and fast memory is even more finite. The more you leak memory, the more often your program will dip into virtual memory pages. This slows the program down and if too much memory is leaked, can crash or freeze the whole machine.

a=(char*)malloc(100); /is ir required coz it refreshes in the next line
a=strste(b,"name");
//if memory allocated in this case so how to free it??
/* memory is allocated and the address is stored in a */
a=(char*)malloc(100);

/* memory leak. a now points somewhere inside b 
and the address returned by malloc is forgotten */
a=strste(b,"name");

//if memory allocated in this case so how to free it??

If you do not have at least one pointer to the address returned by malloc, freeing the memory is impossible. You need to wait until the program ends and the OS reclaims memory for the process. Or if the OS does not reclaim memory for processes, you need to wait until a reboot.

Tom Gunn 1,164 Practically a Master Poster

Isn't the memory released automatically when the program ends?

Yes and no. It depends on how your OS handles processes, but unless you work with some obscure or legacy systems, it is pretty safe to assume that when the program ends, all heap memory allocated to the process is freed by the OS.

The real danger of not freeing your own memory is if your code is reused in something longer lived. I've seen a lot of one off programs get hoisted into a library, and if those programs did not free their memory, they could have killed the hosting program by leaking away memory until a crash or freeze.

Tom Gunn 1,164 Practically a Master Poster

you wont get any benefits from it and i dont even see a specific use

I think it is a great way to explain the simplicity of C++. You will have to fight off the newbies wanting to learn if you show them the clear and intuitive code that can be written:

int main(){X*p;std::cout.operator<<(*(X*)&((*new X(&p))()=10)).put(10);delete p;}

:D

I will leave the simple definition of X as an exercise for the reader.

Tom Gunn 1,164 Practically a Master Poster

Code guards will work everywhere, but #pragma once will only work if the compiler supports it. What's worse, one compiler might define #pragma once to do the same thing as code guards and another compiler might define it to do something completely different. Your code would break on the second compiler.

If you have the option of choosing between two constructs with the same behavior, choose the one that is more portable.

Tom Gunn 1,164 Practically a Master Poster

Why not change the locale to something that uses ',' as the radix character? Then you don't have to do any mumbo jumbo with strings:

#include <iostream>
#include <locale>
#include <sstream>

using namespace std;

int main()
{
    istringstream is("12,34");
    double a = 0;

    is.imbue(locale("german_germany.1252"));

    is >> a; // will recognize ',' as a radix
    cout << a << '\n';
}
jephthah commented: sweet. i lernt something today. +13
Nick Evan commented: as did I. +22
Tom Gunn 1,164 Practically a Master Poster

I did not write the program, I am just taking over.

All the more reason to clean up the warnings too. They will just keep getting in your way, and if you ignore them, one day you will get bitten by whatever they were trying to warn you about.

In a perfect scenario, I'd take some time and would take care of every warning.

In a perfect scenario there would be no errors or warnings. In reality, shipping your code without a clean compile is no different from shipping your code without testing it. I sympathize with you about being under the gun, but producing shit to save time doesn't make you look better than slipping a deadline and producing something of higher quality.

But as of when I asked the question, I was in need of a quick solution : -Wno.

Code quality is the worst place to cut corners. I've pushed back deadlines to get a clean compile before, because I've also been burned by shelving 'minor warnings' to meet a deadline. I kind of hope that your quick solution blows up in your face, because you seem hell bent on learning the hard way instead of listening to others who already learned the hard way.

Tom Gunn 1,164 Practically a Master Poster

>>char EVENT_NAME;

That only declares a single character. you need an array, such as char EVENT_NAME[255]; or better yet string EVENT_NAME;

Please remember that if you use an array with operator>>, you also need to lock the upper limit so that cin does not overflow the array:

char EVENT_NAME[255];

// setw() is declared in the <iomanip> header
// the size for setw includes a null character for the array
while (in >> setw(255) >> EVENT_NAME)
{
    cout << EVENT_NAME << "\t"  << endl;
}

The string class is better because it grows dynamically. You do not need to worry about array overflow or how to deal with extra long strings.

Ancient Dragon commented: Thanks for the correction :) +36
tux4life commented: Nice one here :) +16
Tom Gunn 1,164 Practically a Master Poster

Even the delete operator is executed, the last two output statements are working same the first two output statements..

How is this possible...?????????????????

When you free memory, it may or may not be reused immediately for something else. If it is not reused, you can still access the pointer and get what was there before. But it is not safe to rely on that behavior because there is no way to tell if the memory was reused. The only way to guarantee that you own the memory is not to free it until you are really done with it.

Technically your code invokes undefined behavior because you use a pointer to access memory after it was freed. Undefined behavior is very bad because it makes your program totally unpredictable.

Tom Gunn 1,164 Practically a Master Poster

in order to be able to overload an operator<<,it must be declared as the friend of the class.

Only if the overloaded operator needs access to the private or protected members of the class. If you only touch the public interface, the operator does not need to be a friend:

#include <iostream>

using namespace std;

namespace Daniweb
{
    class Test
    {
        int _x;
    public:
        Test(int x): _x(x) {}
        int operator()() const { return _x; }
    };

    ostream& operator<<(ostream& os, const Test t)
    {
        return os << t();
    }
}

int main()
{
    cout << Daniweb::Test(15) << '\n';
}
Tom Gunn 1,164 Practically a Master Poster
if ( infile ){
	    
		list = read_file( &infile, &lines );   
	        infile.close();

}

I did this and I still get the same result.

When I cout << infile I get an address the first time and 0 the next time.

Ancient Dragon already said you needed to clear the errors too. If you read an ifstream to the very end, the eofbit is set and won't let you do any more reading even if you close the file and open another one. The two states are separate. After closing, clear the error state:

list = read_file( &infile, &lines );   
infile.close();
infile.clear();
Tom Gunn 1,164 Practically a Master Poster

If all of the fields have an overloaded copy constructor or assignment operator, or if they are built in types, you can just do assignments of all fields and everything should work right:

// use copy constructors and initialization
CMatrix::CMatrix(const CMatrix& m)
    : _s_row(m._s_row),
      _s_col(m._s_col),
      base_mat(m.base_mat)
{
    // all work in initializer list
}
// use assignment
CMatrix::CMatrix(const CMatrix& m)
{
    _s_row = m._s_row;
    _s_col = m._s_col;
    base_mat = m.base_mat;
}

The first is recommended because it tends to be more efficient to initialize to what you want instead of default initializing and then assigning what you want.

nanchuangyeyu commented: quite explicit guide +1
Tom Gunn 1,164 Practically a Master Poster

It would be so much better to rely on the standard headers than your memory leaking program.

Technically it leaks memory, but realistically, it is probably not going to be run on an OS that does not free memory when a process ends. As an example of how to allocate memory for a 2D array using new[], the code is fine.

It could be better, of course. :) As an example of both allocating and freeing, the code is more complete and even the technical memory leak is plugged. Good examples of heap memory should free as well as allocate. Here is the better code using the same style as monkey_king:

#include <iostream>


int **allocs(int x,int y){
    int **ret  = new int*[x];
    for(int i=0;i<x;i++)
        ret[i] = new int[y];
    return ret;

}


void deallocs(int **array, int x){
    for(int i=0;i<x;i++)
        delete[] array[i];
    delete[] array;

}


int main(){
    int **array = allocs(4,5);
    int p = 0;

    for(int i=0;i<4;i++)
        for(int j=0;j<5;j++)
            array[i][j] = p++;

    // check the array
    for(int i=0;i<4;i++){
        for(int j=0;j<5;j++)
            std::cout << array[i][j] << ' ';
        std::cout << '\n';
    }

    deallocs(array, 4);

}

I think direct heap allocation should be a last resort. There are so many safer and easier ways than allocating memory yourself, and it takes too much brainpower to make sure that you are not introducing any bugs with your memory handling. A big source of bugs comes from manually handling your memory. That is why the newer languages have garbage collection.

you may want to …

Tom Gunn 1,164 Practically a Master Poster

How aggressive...

It's a sign of how much everyone cares. A good friend will try to stop you from doing something dumb. ;) Out of curiosity, why do you want to disable all warnings?

Tom Gunn 1,164 Practically a Master Poster

Read them the same way you read ASCII files, but you need to convert each character to the right character set once you read it or any output will be jumbled. There are conversion charts all over the web, and the process is simple. Here is one of those charts.

Tom Gunn 1,164 Practically a Master Poster

This might help:

#include <iostream>

using namespace std;

int main()
{
    const int size = 5;
    int a[] = {1, 2, 3, 4, 5};
    int k = 0;

    for (int x = 0; x < 13; ++x)
    {
        cout << x << ": " << a[k++ % size] << '\n';
    }
}

I think a test and assignment is clearer and safer than doing a remainder operation, even though you lose l33t points by doing it the boring way. ;)

#include <iostream>

using namespace std;

int main()
{
    const int size = 5;
    int a[] = {1, 2, 3, 4, 5};
    int k = 0;

    for (int x = 0; x < 13; ++x)
    {
        cout << x << ": " << a[k++] << '\n';

        if (k == size) k = 0;
    }
}