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

char command[argc]

You need to make that an array of pointers: char* command[argc], then before copying the string from argv you will have to call malloc() to allocate memory for each string + 1 for the string's null terminator.

line 8: The for statement is incorrect format. --

char* command[argc];  // older compiles won't like this line
char**command = malloc(argc, sizeof(char*)); // alternate way to do it
for(i = 1; i < argc; ++i) 
{ 
   command[i-1] = malloc(strlen(argv[i])+1);
   strcpy(command[i-1], argv[i]); 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I see you are compiling in UNICODE. Use wtoi() instead of atoi() See this link, or if you want your program to be portable between UNICODE and ascii you can use _tstoi() which is defined in tchar.h

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

Maybe I misunderstand the problem, but if the first two numbers in the file are 9 and 8 then all you have to do is read x and y, then add them todether. There is no need for SUM array. Just delete lines 7 and 9.

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

use CString's GetBuffer() method, similar to std::string's c_str()

int x = atoi(s.GetBuffer());

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

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

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

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

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

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

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

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

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

As for int 3, forget it.

Yes, because the operating system won't let your program execute interrupts. The processors on Intel based computers do not allow normal programs to use int instructions.

Here is more info about int 3 if you are really interested.

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

why do you have a loop? There is no need for it in your example.

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

you need to use an intermediate integer.

int a,b,temp;

temp = a
a = b
b = temp

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

'\n' ( 0x0D hex) represents the value of the Return key that you press on the keyboard. You should become familiar with the data found in ascii charts such as this one. Find 0D in the hex column then look in the Description column where you see "Carriage Return"

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

You might try Sane's Monthly Algorithms Challenges written for beginners through advanced programmers. Warning! Warning! requires some thinking.

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

You should never ever use gets() because it will allow you to enter more characters then the buffer can hold, excess characters are just scribbled all over memory and your program will crash. There are a couple ways to avoid that problem

  1. fgets() -- e.g. fgets(name, sizeof(name), stdin); The problem with fgets() is that it may append '\n' to the end of the string, which your program will have to remove. If '\n' is not present at the end of the string that means there are more keys in the keyboard buffer which your program needs to flush out.
  2. scanf() -- e.g. scanf("%20s", name);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if ((&chouseing_alphabet[0] == abc[0])

Why are you trying to compare the address of a variable with the value of another variable? abc[0] is not an address. If you only want to compare the two characters then remove the & address operator.

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

It depends on the operating system you want to use. On MS-Windows you need a c and/or c++ compiler, such as free Code::Blocks with MinGW compiler or VC++ 2010 Express. On *nix you can use free gcc or g++ compilers.

You can create/compile programs for other operating systems by using a compiler called "cross compiler".

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

you can not delete arrays or other objects that were not allocated with new. All you have to do is delete line 85 because its not needed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

class Student 
{
private:
    int id;
    string name;
    string lname;
    char gender;
    string dob;
    string major;
    double gpa;



public:

    int credits;
    Student();
    void setStudent(int, string, string, char, string, string, int, double); 
    void getStudent();

};
Student::Student()
{   id=6984; name="John"; lname="Trovota"; gender='M'; dob="1/1/1980"; major="CIS"; credits=64; gpa=3.75; }
void Student::setStudent(int i, std::string n, std::string l, char g, std::string d, std::string m, int c, double p) 
{      id=i; name=n; lname=l; gender=g; dob=d; major=m; credits=c; gpa=p;    }
void Student::getStudent() 
{ cout<<id<<"  "<<name<<" "<<lname<<"  "<<gender<<"  "<<dob<<"  "<<major<<"  "<<credits<<"  "<<gpa<<endl; }

bool cmp( Student s1, Student s2 ) {
return s1.credits < s2.credits ;
}


int main()
{
    vector <Student> userData;

    Student s1;
    userData.push_back(s1);
//    s1.getStudent();
    Student s2;
    s2.setStudent(2323, "Brittney", "Speer", 'F', "5/23/1984", "BIS", 78, 2.98 );
    userData.push_back(s2);
//    s2.getStudent();
    Student s3;
    s3.setStudent(1452, "Kathy", "Johnson", 'F', "12/25/1982", "CIS", 30, 3.33 );
    userData.push_back(s3);
//    s3.getStudent();
    Student s4;
    s4.setStudent(4321, "Bill", "Newton", 'M', "7/8/1976", "BIS", 100, 3.95 );
    userData.push_back(s4);
//    s4.getStudent();

    std::sort(userData.begin(), userData.end(), cmp);
    for(size_t i = 0; i < userData.size(); ++i)
        userData[i].getStudent();


    system ("pause");
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look at the code (loop) I posted

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. Delete line 63 --

  2. You have to call getStudent() after the vector is sorted, not before. Call getStudent() from the vector, not the individul Student objects. You need to delete all those lines that call getStudent() and replace them with the following loop AFTER the array has been sorted.

    for(int i = 0; i < userData.size(); i++)
    {
    userData[i].getStudent();
    }

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

Student::credits is NOT a function, which is what the error message told you. Line 38 is wrong -- remove the parentheses.

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

put the cmp() function back the way you had it in your first post, there was no reason to change it. Then just delete line 61 because you don't need a function named sortVecByCreditsAscending.

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

In c and c++ languanges arrays do not have negative index values. If you tried to print that then it is by coincidence that the program worked at all. One reason it may have worked for you is if you declared two integers just before you declared the array so that the program was actually looking at one of the two integers instead of the array. For example

int a;
int b;
int arr[5];
printf("%d", arr[-2]);

If the above does not crash when you run the program what will get printed is the value of variable a. But there is no guarentee that the program will do that either. Because C language does not support negative index values the result of the program is called undefined behavior.

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

Line 47 is too early because the vector doesn't contain anything at that point. Programs run from top to bottom, so the first thing in that main() that gets executed is line 47. You need to move that line all the way down to between lines 59 and 60.

Next, you have to add the 4 objects to the vector. Just declaring them doesn't do that. For example, between lines 53 and 54 you need to add v.push_back(&s2); Do something similar after each of the other student objects have been initialized.

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

You have not populated the vector v with student class objects. After you do that then you can call std::sort() to sort the vector. pass std::sort() the cmp() function you have already written as the last parameter.

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

Strange i run into more errors with C++ than C.

C is an older language, but c++ is a much stricter language. There are lots of things that you can get away with in C that you can't in c++, and C will let you hang yourself a lot faster. Although c++ is derived from C a C program will probably not compile with a c++ compiler without making some changes.

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

delete line 6 and just make normal assignments inside he function. AFAIK you can only do what you did on line 6 with class reference variables, which id_ and name_ are not.

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

ideas or suggestions about what? From the description it appears to be just a simple swapping algorithm, take two pairs and swap their cell values. Most sorting algorithms do something similar. The first step would be to get a pair, 1A for example, then convert it into indices that C/C++ can understand, 1A = 0 and 0

int array[5][5];
char* pair = "1A";
int a,b;
a = pair[0] - '0' - 1;
b = pair[1] - 'A';
int value = array[a][b]
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Interesting ... but you failed to ask the question, or I failed to find it.

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

Will this encourage multiple accounts if emails are different?

That's exactly what happened to me. But then members could always do that. Its only a problem if the member gets banned for one reason or another -- ban one account and all accounts by that member get banned when found. At least that's the way it worked when I was a mod.

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

I mean this button

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

Do you mean which compilers you should use? Of course before you can write a program you have to know something about what the program is to do. For example you can't write a program to fly a ship from Earth to the moon without knowing something about astronomy. You can't write a program that does financial calculations without knowing something about business and/or accounting.

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

Since the table is an array of integers, there is no such thing as null elements, every element has a value. NULL is defined as 0 in most operating systems and compilers, and that's why p[0[0]=NULL doesn't work the way you want it to work. A work-around is to set the element to some number that is not likely to be entered then test for that number. If all the valid numbers are poitive then you can set NULL elements to -1.

for (int col = 0; col < cols; col++)
{
   if( p[row][col] < 0)
      cout << setw(5) << " ";
    else
            cout << setw(5) << p[row][col];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to test for folders. Here's a code snippet that will show you how that's done

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

What about the value of n that I mentioned? Also, the array is not being initialized. The program gets a random number but does nothing with it except display it on the console screen.

Another problem -- rand() does not return negative values, so all you will get are a list of 1000 positive numbers.

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

random_number = (rand()%0)+1;

Why %0 ? That's a do-nothing statement.

line 31, main.cpp. The value of variable n is 0

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

Just change the loop so that i is initialized to sizeOfArray-1, and loop until i == 0

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

It worked ok for me, using this thread as test, then pasted it into Visual Studio and Notapad. How did you copy it to the clipboard? I just double clicked the code, then after seeing it turn blue I right clicked and selected copy from the popup menu.

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

Hydrogen cars are a red herring. I remember my first class in thermodynamics (back in my second year of my Mech. Eng. degree), as a basic introduction to thermodynamics analysis, the prof proved how idiotic it is to even attempt to use hydrogen to power cars

That's what people told Christopher Columbus in 1492. They also said the same thing about people who tryed to learn how to fly, or others like Henry Ford and his horsless carriage. Just because current scientific knowledge doesn't know how to do it, doesn't mean someone someday won't figure out how to do it.

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

cout << "The frequency of letter" <<stats ['A' + i]<<"is"<<stats[i]<<endl;

That line is incorrect -- there is no such element as stats['A'+i] because that's the same thing as stats[64+i]

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

if (ch >= 'A' && ch <= 'Z')

header file: you didn't finish the if statement.

Those two functions in that header file need to be moved to the *.cpp file becuse it will cause duplicate link errors if you include the header file in more than one *.c or *.cpp file. You can safely put function prototypes in header files, but not the entire function.

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

Are you confused because the output is not a double (with some decimal places) or because of the number of digits?

The output isn't a double with decimals because your program is doing integer division, not double division. Typecase either the numerator or denominator to double and it will do double division. Typecasting the entire result to double doesn't do the same thing.

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

One way to avoid all those if statements is to set up an array of function pointers and parameter strings, then you can use a loop to iterate through the array to match the input parameters with the parameter strings in the array's structure. If the structures are in sorted order then you could use a binary search algorithm to find the function you want, or put the strings in a binary tree for searching.