Click here to Skip to main content
15,881,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIPersistFile::Save fails Error Access Denied Pin
ShilpiP10-Apr-10 17:56
ShilpiP10-Apr-10 17:56 
AnswerRe: IPersistFile::Save fails Error Access Denied Pin
Adam Roderick J10-Apr-10 20:59
Adam Roderick J10-Apr-10 20:59 
GeneralRe: IPersistFile::Save fails Error Access Denied Pin
ShilpiP11-Apr-10 5:52
ShilpiP11-Apr-10 5:52 
QuestionUsing a Dialog as a Control in another Dialog Pin
Bram van Kampen10-Apr-10 17:24
Bram van Kampen10-Apr-10 17:24 
AnswerRe: Using a Dialog as a Control in another Dialog Pin
Gary R. Wheeler11-Apr-10 1:14
Gary R. Wheeler11-Apr-10 1:14 
GeneralRe: Using a Dialog as a Control in another Dialog Pin
Bram van Kampen11-Apr-10 2:13
Bram van Kampen11-Apr-10 2:13 
GeneralRe: Using a Dialog as a Control in another Dialog Pin
Gary R. Wheeler11-Apr-10 13:22
Gary R. Wheeler11-Apr-10 13:22 
QuestionProblem with reading big amount of numbers from file Pin
vonpik10-Apr-10 13:18
vonpik10-Apr-10 13:18 
Hi! I have to do a project for my studies. It is a insertion algorithm.
I'm reading data from file with using vector.
then I'm copying vector to a normal array (the reason is simple: I don't know how to send vector to function, but this is not a main problem).
After copying, I'm sending (with using pointers) array to sorting function.
Everything is good, algorithm is working but! (yep, there is always but... Wink | ;)
When I save a lot of data to file, program just after start crashes.

The numbers in file are written in that way:
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

So there are 40 numbers in one line. I have 4.000 lines, so after simple math we have 160.000 numbers. The main problem: when I add some new numbers for example 40.000 program crashes
I must have more numbers because the task is to compare few sorting algorithms with minimum 15 minutes of sorting. (160.000 digits is sorting in ~1 minute)

Here's the code. Maybe it is poor written, but I did my best.

//written with Qt
#include <QtCore/QCoreApplication>
#include <iostream>
#include <time.h>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

//sorting function
void insertion_sort(int *wsk, unsigned long size);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    //vector to hold data from file
    vector <int> array_vector;

    //stream to file
    ifstream plik ("numbers.txt",ios::in);

    //single number that is being readed from file    
    unsigned long single_number;

    
    while(plik >> single_number)
    {
        array_vector.push_back(single_number);
    }

    int array_nonsorted[array_vector.size()];
    //copying from vector to array
    for (unsigned long a = 0; a < array_vector.size(); a++)
    {
        array_nonsorted[a] = array_vector[a];
    }

    time_t start,end; double long dif;

    cout << "START\n";
    time(&start);
    insertion_sort(array_nonsorted,array_vector.size());
    time(&end);
    cout << "STOP\n";
    dif = difftime(end,start);
    cout << "Array sorted in " << setprecision(5) << dif << "sec"; dif = dif/60; cout << " = " << dif << "minutes";
    //cout << "End.";
    return a.exec();
}
void insertion_sort(int *wsk, unsigned long size)
{
    int tab_sorted[size];

    //In final version I will do this by using pointers. I'm just copying it because with using pointers it's hard to see data in debugger
    for(unsigned long i = 0; i < size; i++)
    {
        tab_sorted[i] = wsk[i];
    }

    //main sort engine

    for (unsigned long a = 1; a < size; a++)
    {
        if (a == 1)
        {
            if (tab_sorted[0] > tab_sorted[1])
            {
                unsigned long temp = tab_sorted[0];
                tab_sorted[0] = tab_sorted[1];
                tab_sorted[1] = temp;
            }
        }
        else
        {
            for (unsigned long b = 0; b <= a-1; b++)
            {
                if (tab_sorted[a] < tab_sorted[b])
                {
                   unsigned long temp = tab_sorted[a];
                   for (unsigned long c = a; c > b; c--)
                   {
                       tab_sorted[c] = tab_sorted[c-1];
                   }
                   tab_sorted[b] = temp;
                }
            }
        }

    }
}

So why the program crashes? I don't have a clue Frown | :( Something with memory (but I have 3.0GB and OS works normally when program is starting). Please help!
Luk.

QuestionRe: Problem with reading big amount of numbers from file Pin
Tim Craig10-Apr-10 13:46
Tim Craig10-Apr-10 13:46 
AnswerRe: Problem with reading big amount of numbers from file Pin
vonpik10-Apr-10 14:11
vonpik10-Apr-10 14:11 
GeneralRe: Problem with reading big amount of numbers from file Pin
Tim Craig10-Apr-10 19:37
Tim Craig10-Apr-10 19:37 
GeneralRe: Problem with reading big amount of numbers from file Pin
vonpik11-Apr-10 12:16
vonpik11-Apr-10 12:16 
QuestionRe: Problem with reading big amount of numbers from file Pin
David Crow11-Apr-10 15:54
David Crow11-Apr-10 15:54 
AnswerRe: Problem with reading big amount of numbers from file Pin
vonpik13-Apr-10 10:05
vonpik13-Apr-10 10:05 
GeneralRe: Problem with reading big amount of numbers from file Pin
David Crow13-Apr-10 10:16
David Crow13-Apr-10 10:16 
GeneralRe: Problem with reading big amount of numbers from file Pin
vonpik16-Apr-10 3:43
vonpik16-Apr-10 3:43 
GeneralRe: Problem with reading big amount of numbers from file Pin
David Crow16-Apr-10 4:41
David Crow16-Apr-10 4:41 
Rant(*&#@*!^ Templates PinPopular
Tim Craig9-Apr-10 20:40
Tim Craig9-Apr-10 20:40 
GeneralWelcome Pin
CPallini10-Apr-10 4:43
mveCPallini10-Apr-10 4:43 
GeneralRe: Welcome Pin
Tim Craig10-Apr-10 21:30
Tim Craig10-Apr-10 21:30 
GeneralRe: (*&#@*!^ Templates Pin
Gary R. Wheeler11-Apr-10 1:31
Gary R. Wheeler11-Apr-10 1:31 
GeneralRe: (*&#@*!^ Templates Pin
Tim Craig11-Apr-10 9:36
Tim Craig11-Apr-10 9:36 
QuestionProblem in AT+CSCA command in AT commands. Pin
Le@rner9-Apr-10 19:29
Le@rner9-Apr-10 19:29 
Questionhow to implement three indepedent random number generators in the same subroutine/function Pin
mrby1239-Apr-10 17:34
mrby1239-Apr-10 17:34 
AnswerRe: how to implement three indepedent random number generators in the same subroutine/function Pin
Adam Roderick J9-Apr-10 18:09
Adam Roderick J9-Apr-10 18:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.