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

Yes, it has focus. The only time Esc works is if I first hit Insert Code Snippet button, get an error message, press the Ok button on that window, then Esc will close the code window.

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

I did "read here", that's why I commented on getline(). If that's a C function in gcc then I'd suggest not usuing it either because it isn't portable, just as everything in conio.h isn't portable. Non-portable code has always been discouraged here.

The getline function is the preferred method for reading lines of text from a stream, including standard input.

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

Esc doesn't close the window, at least it doesn't work in IE9. Maybe you should put a Cancel button on the code window.

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

getline() is a c++ function not useful in C programs. As for fgets() being unreliable, it isn't if you use it correctly.

If you know bigDaddy is big enough why not just use that as the parameter to fgets() instead of buf? In any event, the program needs to execute line 8 regardless of whether the '\n' exists or not because otherwise bigDaddy won't contain all the data.

It might be better to make bigDaddy a pointer so that memory can be allocated to it as needed. In the loop just reallocate bigDaddy to hold the curerent string plus the new string.

char* bigDaddy = NULL;
char buf[BUFSIZE];
char* ptr;
while( fgets(buf,sizeof(buf),fp) )
{
    bigDaddy = realloc(bigDaddy, strlen(bugDaddy)+strlen(buf)+1);
    strcat(bigDaddy, buf);
    if( (ptr = strrchr(bigDaddy,'\n')) != NULL)
    {
        *ptr = '\0';
        break;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I haven't see it and I'm using IE9 which I just reinstalled last night.

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

Since code always contain line numbers (at least in the C/C++ forums it does) I see no reason to quote it, just refer to the line number(s) should be sufficient.

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

Nermind, I think it is my computer. Used another computer and IE9 worked as expected.

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

It works ok in Chrome, so it must be an IE9 problem where the login screen does not appear.

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

When you create a DLL the compiler will generate two files -- one with dll extension and the other with lib extension. Then when you compile the application program (console or windows) you tell the commpiler to link with the DLL's *.lib file. You will have to manually create a header file that prototypes the functions you exported in the DLL so that the header file can be used in the application program.

Here are some google links and videos you will want to study.

so can i change the console application to windows application..i have interface that need to make a dll..can i do that??.

Generally, yes.

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

count the rows as the data is entered. When you enter a negative value then stop the loop. For example:

int row = 0;
int value = 0;
int done = 0;
while( !done && row < 10)
{
   int i;
   for(i = 0; i < cols; i++)
   {
      scanf("%d", &value);
      if( value < 0)
      {
         done = 1;
         break;
      }
      array[row][i] = value;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Note: If you want to write this program on MS-Windows os you may have to use _open(), _read(), and _close() instead of the functions specifid in your assignment. Also include header files io.h and fcntl.h

There are a couple ways you can write the program:

  1. Just use an array of char pointers and malloc() memory as the data is read from the file.

  2. Create a linked list of lines, assuming you have studied linked lists. This is the most efficient method because you don't have to know beforehand how many lines are in the file.

In either event, start out by reading the file one character at a time, putting each character into a char array whose size is just hard-coded in the program. When the line separator is reached (it will be either "\r\n", "\r" or "\n" depending on the operating system) add he new line to the array of linked list. Note that you will have to malloc() additional memory for this step.

After you get the above coded, compiled and tested you can begin working on the rest of the assignment.

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

The best way is to use portable libraries such as QT and boost. That way you write just one program without all those preprocessor statements. There are quite a few cross-platform libraries to choose from, which one you choose will depend on what you are trying to accomplish.

I've heard that there is a C# compiler for *nix, but I've never tried it. You might want to read a few of these google links.

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

It will also depend on your network connection speed. I'm also using Chrome, my rep graph is pretty large, and my profile page loads with no problems. Maybe there should be an option to turn off that graph so that people with slow connections don't have to wait so long.

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

Generally GUI programs can have other threads that do background work such as performing long calculations. Post your program and compiler's error messages that you can't get to work and we will see how to help you.

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

I don't quite understand how the data is to be sorted. Is it according to column 2 minus the value of column 3?, for example for Kelvin it would be 170-58 = 112

Put the data into a structure then sort the structures

struct data
{
   char name[20];
   int a1;
   int a2;
   int diff;
 };

 struct data array[255];

Read the data into the above array then sort the array on member variable diff.

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

So you can do something like this

Or just use sprintf()

char filename[40];
sprintf(filename,"03/%s.txt", sn);
// filename = "03/1234.txt"
dx9_programmer commented: haha yes of course +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I used vc++ 2012 RC to debug the program. The problem is that the value of elm in function eval() is '\0' and the switch statement doesn't handle that value so it returns crap since you didn't initialize the return variable. The string returned by in_to_post() has an embedded '\0' which I believe is why eval() is getting '\0' as a parameter. std::string.length() returns the total size allocated to the string, unlike strlen() which stops counting then '\0' is encountered. So the loops using st.length() in the condition may not be working the way you want because of the embedded '\0'.

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

I think you misunderstood him -- he meant to say "in my opinion"

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

You need to create a structure that holds the information for one person, then create an array of those structures. As the file is read you will populate each of the structures in the array. After file reading is finished, you need to sort the array of structures. There are many algorithms for sorting, so you need to know which algorithm you are to use.

If you know how to do linked lists then sorting isn't necessary because you can add the structure to the list in sorted order.

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

You can do what deceptikon suggested or just declared the string as

Almost right, you need to surround string literals with _TEXT() macro or _T() macro, they are both the same.

TCHAR temp[10] = _TEXT("abcd");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You won't find anyone here who will write your program for you, so you might as well try to do it then post the questions you have.

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

You can't have variable names the same as function names.

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

what you need to solve that problem is to study is probability theory, not computer science. Pay attention to the section Discrete probability distributions

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

You can export the entire class without specifying individual methods like below code snippet. For more thorough explaination see this link

class __declspec(dllexport) Derived :
    public Base
{
    ...

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

So now it runs but again doesn't calculate the retail price for me.

Because it's not calling RetailPrince() function. Your program is passing a pointer to the function, not calling the function itself. This is how it should be coded, note the last parameter is calling the function.

Store InventoryItem (InitProductIDNumber, InitDescription, InitManufacturersIDNumber, InitPrice, InitPercentage, 
            InitInventory, RetailPrice());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

repost lines 39 and 40 so we can see what changes you made.

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

line 40: That ctr is expecting a double as the last parameter, not a pointer. Remove the & before RetailPrice.

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

Without better formatted code I can only guess the problem is mismatched { and }.

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

lines 22-27: if statements that have more than one line require { and } around them.

line 24: use a different variable because j is used as loop counter on line 22.

line 25: That line does nothing. You need something like this: A[j][i] = X; where X is the value return by scanf() in the previous line.

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

Could be this problem

triumphost commented: Similar +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 26: never, ever for any reason call main() from within your program. That function is reserved for call by the operating system, not your program. Instead, add a loop around all that code.

line 33: syntax error because that line isn't inside any function, at least I don't think so because the code is not formatted very well. Indent the code correctly and you will be able to easily see the problem. It looks like line 32 is the start of temperature function, but { and } are missing around it.

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

line 18: can't do that because there is no memory allocated for the vector.

Data.push_back(Pixels[(Foo.Height() - 1 - I) * Foo.Width() + J].RGBA.B);

If you can calculate the size needed beforehand, then call Data.Resize(X) to allocate all the memory at one time, then I think the rest of your program will work as written.

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

wait a minute

Time's up :)

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

The screen shots are unreadable -- copy and paste your code into DaniWeb's code editor so that we can see it better.

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

time() gives you the current time, but in seconds. If you want to test for two keys within a certain number of milliseconds all you need is the value returned by clock(), then subtract the two values, you don't care what the current time is.

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

and i would display it using fgets correct?

Not quite, remove the & before the three variable names. You don't need to put & to get the address of a char array.

lines 30-35: Notice that the three if statements are all identical. In order to get the correct file name there must be three distictively different test conditions.

Also, I think you want && not ||. You want to test for John AND Wanth AND Doend in order to read file named 03/1234. There might be two or more files that duplicate any one or more of those names, so to get the right one all three must be present at the same time. Very similar to the way you would find someone in a telephone book.

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

don't use a macro to declare a variable -- just too confusing.

Does the second buff overwrite the first one

Depends on where the first one is declared. If its in the same block enclosed with { and } then there will be a compiler error for duplicate symbol. If the first one is somewhere else then the compiler may produce just a warning or nothing at all. In that case the second declaration will override the first.

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

lines 35 and 48: don't use while statements, just simple if will do because all its doing is testing if the file is open, and if not exiting the progrm. while is unnecessary.

line 50: while not necessary here either. If the file was opened correctly then everything within that while statement will get skipped because inFile will not be NULL and your program isn't reading anything from the file.

The code you posted osn't reading the input file at all, just getting data from the keyboard.

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

Your macro is wrong

#define BUFFEFR_SIZE 5

You don't put a variable name in the macro

char buf = BUFFER_SIZE;

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

ignore the above -- you started another thread.

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

It's not a pointer problem, just output problem. Try adding fixed to cout

outFile << "Value: " << fixed << company[i].budget_value << endl;

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

post the whole program. This works ok for me using vc++ 2012 RC

#include<string>
#include <iostream>
#include <fstream>
using namespace std;

struct budget
{
    int budget_num;
    string name;
    float budget_value;
};

const int SIZE = 15;
int main()
{
     budget company[SIZE], *ptr;
     ifstream inFile("ledger.dat");
     ofstream outFile;
  //while(!inFile)
    {
        //Same junk output for this
        for(ptr = &company[0]; ptr < &company[SIZE]; ptr++)
        {
            cin >> (*ptr).budget_num;
            cin >> (*ptr).name;
            cin >> (*ptr).budget_value;
        }

        //As this
//        for ( int i = 0; i < SIZE; ++i )
//        {
//            cin >> (company[i].budget_num);
//            cin.ignore();
//            getline(cin, company[i].name);
//            cin >> company[i].budget_value;
//            cin.ignore();
//        }

    }

    for(int i = 0; i < SIZE; i++)
    {
    cout << "Number: " << company[i].budget_num << endl;
    cout << "Name:   " << company[i].name << endl;
    cout << "Value:  " << company[i].budget_value << endl;
    cout << endl;
    /*
    outFile << "Number: " << company[i].budget_num << endl;
    outFile << "Name:   " << company[i].name << endl;
    outFile << "Value:  " << company[i].budget_value << endl;
    outFile << endl;
    */
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you should divide it with ticks_per_second so as to get the time

That give you seconds since the program started, not the current time. one tick = one millisecond.

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

Or you could just write your own program. What's so difficult about writing a program that does nothing more than blindly split a file into small chuncks? It could be written in maybe 15 minutes. Of course people who don't know how to program couldn't do that, but that's not the case here.

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

clock() is a stanadard function that's in (usually) milliseconds.

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

there is no such index value as company[15], the indices are numbered 0, 1, 2, ... 14. A safer loop is to use integer, not pointer, in the for statement. Attempting to use ptr like you did is not safe because it depends on how the computer's memory is laid out

for(int i = 0, ptr = company; i < 15; i++, ptr++)
{

|

Finally, declare a const int to represent the number of elements in company so that you can easily change its value whenever you wish with little effort.

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

If you marked the thread solved and later find that you have more questions about the same topic you can change the thread to unsolved then continue the discussion.

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

This time I will use abort() to close the program. That's the most efficient way, I think.

No, its not. The most efficient way is to return from main(). If you want to close the program from somewhere else then call exit(), not abort().

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

Hummm -- I think Dani needs to sue Microsoft for about $10 Billion because DaniWeb had that color scheme first.