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

Two problems with that code
1. theData in Data() is just a local variable, so line 12 us useless, does nothing.
2. arrays declared inside function can not be returned from the function, attempting to do so will cause sig faults, as you have found out.

To correct the problem, move line 9 to line 17 so that it is declared inside main() instead of Data, then pass it as the parameter to Data(). You will also have to pass the size of the array as another argument to Data() because sizeof does not return the size of an array when used with a pointer.

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

post the structure

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

I should mention that there is no function in the standard library for deleting files

Yes there is -- remove()

The same applies to renaming a file.

See above link

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

Do you have a *.h file and/or *.lib that does along with the dll?

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

i didn't even have a code to show you cause I know its wrong.

That doesn't matter here -- most of the code we see posted here is wrong. All we require is that you make an effort to write your program, we don't require the code be correct.

researching for ifstream.h and ofstream.h....and so far ifstream.h is for reading a file, and ofstream.h is for writing to a file right??

No. There are no such header files. fstream, ifstream and ofstream are all declared in the same header file named fstream.h (current compilers use <fstream> instead of <fstream.h>

If you can you should upgrade your compiler to either Code::Blocks or VC++ 2010 Express, both are free. If you live in India then you may not have that option because your school most likely requires Turbo C.

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

You are very close -- only five problems marked with // <<<< in the code below

#include<iostream>
using namespace std;

struct process{
    int processId;
    int burstTime;
    int arrivalTime;
};

int main(){
    int numberOfProcesses;
    const int maxprocesses = 10;        //<<<<<<< these two lines were declared in the wrong place
    struct process p[maxprocesses];     //<<<<<<< ^^^^

     //number of process
    cout <<"please enter the number of process: ";
    cin >> numberOfProcesses;



    // initialize variables
    int smallest_burst = p[0].burstTime;
    int smallest_burst_index = 0;
    int smallest_arrivalTime = 0;
    int smallest_arrivalTime_index = 0; // <<<< Can not be initialized here



     // get burst time , arrival time
     for(int i=0; i<numberOfProcesses; i++){
        p[i].processId = i;
        cout << "p" << i << ":" << endl;
        cout <<"Burst time: ";
        cin >> p[i].burstTime;
        cout <<"Arrival Time: ";
        cin >> p[i].arrivalTime;
      }
    smallest_arrivalTime = p[0].arrivalTime; // <<<<<< Initialize variable

       //display user input
      cout<<"Process" << "\t" << "Burst" << "\t" << "Arrival" << endl;
      for(int i=0;i<numberOfProcesses;i++){
          cout <<"P" << p[i].processId << "\t" << p[i].burstTime << "\t" << p[i].arrivalTime <<endl;
      }



     // after computing
    for(int i = 1; i < numberOfProcesses; ++i) // <<<<<<<<<<<<<
    {
       if(p[i].burstTime < smallest_burst)
       {
           smallest_burst = p[i].burstTime;
           smallest_burst_index = i;
       }

        if(p[i].arrivalTime < smallest_arrivalTime)
       {
           smallest_arrivalTime = p[i].arrivalTime;
           smallest_arrivalTime_index = i;
       }
    }

      //display
      cout << endl;
    //  cout<<"Process" << "\t" << "Burst" << "\t" << "Arrival" << endl;
      cout << "Sortest Arrival Time: " << p[smallest_arrivalTime_index].arrivalTime << '\n';
        cout << "Burst Times: \n";
        for(int i = 0; i < numberOfProcesses; ++i) // <<<<<<<<<<<<<
        {
           if( i …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well , can you please define what is 2:6-7 ,

You mean to tell us you are trying to debate in this thread without knowing anything about the topic????? 2:6-7 means chapter 2 verses 6 and 7. For the Quran see the link in my previous post. Anyone who has ever read parts or all of the Bible or Quran should have known that 2:6-7 means. I'm flabbergasted.

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

2:6-7 Don't bother warning the disbelievers. Allah has made it impossible for them to believe so that he can torture them forever after they die.

It says no such thing. Here is the English translation

2:6 Those who disbelieve — it being alike to them whether thou warn them or warn them not — they will not believe.

2:7 Allah has sealed their hearts and their hearing; and there is a covering on their eyes, and for them is a grievous chastisement.

The Christian Bible teaches us the same thing -- if you don't believe in Jesus and God you will burn in Hell for all eternity.

4:89 They long that ye should disbelieve even as they disbelieve, that ye may be upon a level (with them). So choose not friends from them till they forsake their homes in the way of Allah; if they turn back (to enmity) then take them and kill them wherever ye find them, and choose no friend nor helper from among them.

Again, that conflicts somewhat in the translation I posted. But the gist of it is the same - once a Muslem always a Muslem, and kill anyone who wants to do otherwise.

4:89 They long that you should disbelieve as they have disbelieved so that you might be on the same level; so take not from among them friends until they flee (their homes) in Allah’s way. Then if they turn back (to hostility), seize them …

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

People that buy guns should first pass a mental competency test

Why? How is that any different than people who buy table knives? or hunting knives? or baseball bats? All of those can kill people.

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

Bubble sort is a bitch with linked lists

Not really. See function Sort() in the code below

#include <iostream>
#include <cstdlib>
#include <ctime>

class Node
{
public:
    Node(int d) {setData(d); next = NULL;}
    int getData() {return data;}
    void setData(int d) {data = d;}
public:
    Node* next;
protected:
    int data;
};

const int MaxNodes = 10;

Node* GetTail(Node* head)
{
    if(head == NULL) return NULL;
    while( head->next )
        head = head->next;
    return head;
}

void ShowNodes(Node* head)
{
    while(head)
    {
        std::cout << head->getData() << '\n';
        head = head->next;
    }
    std::cout << "\n";
}

void InsertTail(Node**head, int d)
{
    Node* newnode = new Node(d);
    Node* n = GetTail(*head);
    if(n == NULL)
        *head = newnode;
    else
        n->next = newnode;

}

void Sort(Node* head)
{
    Node* t1, *t2;

    for(t1 = head; t1->next != NULL;t1 = t1->next)
    {
        for(t2 = t1->next;t2 != NULL; t2 = t2->next)
        {
            if( t1->getData() > t2->getData() ) 
            {
                int temp = t1->getData();
                t1->setData(t2->getData());
                t2->setData(temp);
            }
        }
    }
}


void FreeNodes(Node** head)
{
    Node* curr = *head;
    while(curr)
    {
        Node* n = curr;
        curr = curr->next;
        delete n;
    }
    *head = NULL;
}

int main()
{
    Node* head = 0;

    srand((unsigned int)time(0));
    for(int i = 0; i < MaxNodes; i++)
    {
        InsertTail(&head,rand());
    }

    ShowNodes(head);
    Sort(head);

    ShowNodes(head);

    FreeNodes(&head);



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

see his post two days ago on page 4

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

If you want to show all processes in ascending order by burst time then sort them by burst time. No need to sort by arrival time, just get it as previously posted.

cout << "Sortest Arrival Time: " << p[smallest_arrivalTime_index].arrivalTime << '\n';
cout << "Burst Times: \n";
for(int i = 0; i < maxprocesses; ++i)
{
   if( i != smallest_arrivalTime_index )
       cout << p[i].burstTime << '\n';///

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

use bubble sort algorithm (the easiest to code) and sort the list by number. When a swap is needed just swap the data within the node structure, not the nodes themselves.

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

can you post some same data? Need to know what's in the file and how its formatted.

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

I thought it was probably something like that.

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

Is userip char*? If yes, then to put a space before it you will have to move current text right one character to open up the byte in which to put the space.

For example, if userip originally contains "255.255.255" then you will call memmove() to shift all characters right one byte

memmove(&userip[1],userinp,strlen(userinp));
userip[0] = ' ';

Warning! userip must be declared large enough to hold the extra characters.

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

I tried that link, my entire screen turned white, pressing Esc did nothing, so I killed the browser in Taek Manager.

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

It depends on how the log file was written. If it is in binary mode and written with fwrite() then you can use fread() to read each record directly into the structure. Otherwise if its text mode and written with fprintf() then use fgets() to read it and pars the line into individual fields, then populate with structure members with that information.

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

You don't need c++ at all to learn GUI -- afterall, it was originally written in C, not c++. As long as you have basic understanding of c++ you should be fine with QT. Anything you don't know now you can easily pick up while working with QT.

note : sry for the bad english

Please stop saying that. There is nothing wrong with your English.

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

note : sorry for the bad english

Don't underestimate your command of Engligh language -- its much better than many native English writers I've seen.

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

how it works depends on the hardware. If you buy a small robot then you will have to read their programmer's documentation to find out how to interface a computer with it. If you build your own then I suppose you can design the commands yourself. You might want to start out by googling for "robotics"

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

The first thing to do is design the database. What database engine do you want to use? MySQL, MS-Access, Orical, ... there are dozens of them. Do you know SQL? If not then you will have to study/practice it. There are lots of books on amazon.com that help you with that. Use google and you might even find free "sql tutorials".

Once the above is done, you need to take pencil & paper in hand and design the layout of the screens and write down what each of the buttons, list boxes and check boxes will do. This will give you a clear understanding of what your program will do and what functions you need to write.

Once all the above is completed you can begin coding. If you try to code beforehand you will wind up recoding stuff that doesn't work and wasting a lot of your time. You can still make a few design changes after you start coding, but that will probably not happen often, if at all.

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

int k=12;

Now try this and you will see different behavior
static int k=12;

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

Its not that simple -- see this article

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

why templates? So that you don't have to write different functions that all do the same thing but with different data types. That's how its done in C language. For example if I need a function that returns the sum of two numbers but it need to handle int, float, and double, one way to do it would be to write three different functions, one for each data type. The more efficient way to do it is to write just one template that returns the sum of two numbers of any data type.

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

use strlen

Maybe, but maybe not. Depends on what you want, strlen() and sizeof() may return different values such as when the buffer contains embedded '\0' characters.

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

variable a is an single dimensional array which will hold only one string. What you want is something like this: char a[20][30]; which is a 2d array that holds up to 20 strings, and each string can contain up to 30 characters (29 + null terminator).

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

You are assuming that all of us have the mental capacity of great thought processes. Just because you have a Ph.D. in Thought Processes doesn't mean everyone has that capacity. Most people are like sheep who blindly follow a leader.

Belief in a God is really a gamble, and we won't find out whether or not its true until we die. If there is no God and no afterlife, then no harm done. But ... the alternative is pretty awful for someone who believed there is no God. Its too bad we have to wait until we die to find out one way or the other. If no God, then no reason to have morality, and with no morality there would be chaos.

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

There is no such thing as "simple" example. You have to use win32 api Communications Functions. After calling CreateFile() to open the serial port you will have to fill out a DCB structure, then call BuildCommDCB(). After than you call ReadFile() and WriteFile() to read/write to the port. Here is a c++ class that you might want to study

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

function pointers can only point to static class methods or global c-style functions. You will have to make PrintIt() a static method if you want to do that.

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

i understand my memmove output but why it is same as memcpy?

Both functions produce the same results. The only real difference is whether the destination and source buffers overlap. If they don't, then use memcpy(), otherwise if they do then use memmove().

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

Here is a detailed explaination of code and data segments, and how the computer's memory is laid out. In a nutshell, programs are devided into two parts -- code and data. Code segment is where the executable statements reside, data segment is there all the variables and the program's stack resides.

memoery alocated to variables is at run time or compile time

All variables are actually allocated at runtime, that is to say that very little, if any, is actually put into the executable program that resides on disk. When the program is loaded into memory the program loader allocates memory for all global variables and then calls main() function. Memory for local variables are not allocated until the function is called, as I described in my previous post.

Programmers try to avoid global variables as much as possible because they can cause a lot of confusion. You can legitimately have both local and global variables with the same name, when that happens the local variable is used instead of the global variable. If the programmer isn't aware of this he can spend hours trying to figure out why the global variable isn't changed when its supposed to be (I've been there and done that :) )

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

If a[0][0] and a[0][1] are both null-terminated strings, then you have to call strcmp() to check of the two strings are the same. The following will produce a two-dimensional array of strings that contain up to 40 characters each.

char a[2][2][40];
strcpy(a[0][0],"Hello");
strcpy(a[0][1],"World");

if( strcmp(a[0][0], a[0][1]) == 0)
{
   printf("Both strings are the same\n");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can anyone explain ...at what time memory is allocated for variables...

Intel based computers -- All local variables are actually allocated by the compiler immediately upon function entry, even the variables that are declared later within the function. (You will see this if you let your compiler produce an assembly language version of your program) The compiler will rearrange variable declarations so that they appear as if you had declared them all at the beginning of the function. Memory for these is released as soon as the function returns to its caller.

Memory for global variables are always allocated at compile-time and stored in a data segment that is completely separate from code segments. Memory for these are not released until the program itself is terminated.

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

It would be helpful to know what the error message(s) are.

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

display it like thiks example: smallest arrival time is
p[smallest_arrivalTime_index].arrivalTime;

Also -- delete the loop on line 66 and if statement on line 70, there is no reason for them. All you want left there is line 72 and line 75.

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

Visual C++ used to have support for makefiles

It still does -- Visual Studio 2012 RC

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

That's another thing you both have in common "persistence"

No, its more common with computer programmers.

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

Can some one list all the functions in windows.h

You will have to buy a book to get that kind of information. See any of these

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

Our gun deaths are a mere fraction of yours.

Most likely because most of Canada is frozen wasteland.

Here are some interesting data, a little old but interesting.

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

This code compiles with vc++ 2012 RC, but its not tested.

void foo(int n2, vector<int> a)
{
    int temp, cnt;
    vector<int>::iterator y;
    for (int i = 0;i<n2;i++)
    {
            cin>>temp;
            cnt = 0;
            y = lower_bound(a.begin(),a.end(),temp);
             if (*y == temp) cout <<temp<<"found at"<<int(y-a.begin()+1)<<endl; 
             else cout<<temp<<"Not found"<<endl;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See the example here. Delete fstream from your program because it won't work with Windows Forms, which is CLR/C++, not c++, two different languages.

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

It is pointless to propose a hypothesis that cannot be tested either by experimentation or observation.

As a general rule of thumb, maybe yes. But astrologers do it frequently, e.g. searching for life on other planets, or extraterrestial life here on Earth. Fasinating topics.

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

scientists don't waste their time doing research to answer questions that are non-sensical)

Yes they do, scientists do that all the time. That's why we now know the Earth is round and that it revolves around the sun. I also know of one who tried to prove a strong correlation between the rising moon and pregnancy. Or other scientists who study the breeding habits of flys.

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

See thumbnail. This is what I see after pressing the Edit Post link. The edit box with the big red arrow is the second one I am talking about.

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

I live in Illinois -- two of the last three governors are in prison right now for curruption.

Power tends to corrupt, and absolute power corrupts absolutely. Great men are almost always bad men, even when they exercise influence and not authority: still more when you superadd the tendency or the certainty of corruption by authority.
Lord Acton,in a letter to Mandell Creighton (5 April 1887), published in Historical Essays and Studies (1907).

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

I gave you three examples which you have chosen not to respond

You gave me no examples of any laws that are discriminatory. Requiring a photo id in order to vote violates no ones rights. Can't afford to get a photo id? Then stop spending money on drugs, hookers, having a baby every 9 months, and Big Macs.

As for the guy that got three life sentenses, I'm surprised he doesn't sue for unusual and curel punishment. Maybe he has, but that was a very interesting article you posted. I'm with you on that one. Unfortunately the War on Drugs program is a failure, and has been for some time now.

BTW: if you think I'm Republican, I'm not. I voted for Obama in the last election and intend to do so again. Mitt Romney was the best thing the Republicans could have done to assure Obama a second term.

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

hey..m a student of last year of BCA

Please STOP posting as though you were texting on your cellphone. This is a forum, not a cellphone. If you expect people to take you seriously then you need to spell out the words. There are lots of people here who do not know Engligh well enough to understand what you wrote.

sfuo commented: Engligh! +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move lines 9 and 43 down into main() then pass the file2 to print() as a parameter. Open the file only once, just before the loop that starts on line 69. Also, fstream objects must be passed to other functions by reference.

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

Bush claimed that "God" told him to invade Iraq.

Proof???