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

>>program is running fine from the tc
I guess that means Turbo C compiler ?

Sounds like the csv file is not where you think it is. Check to see that it is located in the same directory as the *.exe file. If not, then did your program specify the full path to the file in the open statement ? [edit]see line 535 of the code you posted[/edit]

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

Don't do it like that because it would cause a huge security risk. Instead, have the client pull the file from the server, run it and send results back to server.

>>Plz give me hint or any sample code???
Client/server sample code ? You can find some at DataReel.com. Free library that contains lots of code, including client/server

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

after using cin call peek() to see if the next character is '\n' or not.

int x;
cin >> x;
if( cin.peek() != '\n')
    cout << "Bad\n";

Or get it as a string and check each character.

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

line 57 main.cpp: g.calcAvgHandi(handi, count);
handi is an int, not an array. Similar problems with the other lines.

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

This has not been compiled or tested, so it might or might not contain bugs.

void log(const char*msg)
{
    time_t now = time(0);
    struct tm* tm = localtime(&now);    
    ofstream out( "logfile.txt",ios::ate);
    out << tm->tm_year << '/' << tm->tm_mon << '/' << tm->tm_mday
         << ' ' << tm->tm_hour << ':' << tm->tm_min << ':' << tm->tm_sec << ": ";
    out << msg << "\n";
    out.close();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

log files are just simple text files. I usually put the date/time at the beginning of the log entry. I wouldn't bother with any of the MFC file functions such as CFile and CArchive. Use normal fstream objects. The log function should open the log file, write the log entry then close it again.

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

I don't know. Maybe ask them if they have tutorial or sample code ?

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

Pass the open stream to each function as a parameter.

void func1(ifstream& in)
{

}

void func2(ifstream& in)
{

}

int main()
{
   ifstream in("myfile.txt");
   funct1(in);
   funct2(in);

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

what part of findMe () don't you know how to code ? Look at this line and you will see what parameters it needs to have. All parameters should be passed by reference. if (findMe(lookmeup, names, score, tmpscore))

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

According to those pictures men also have much lower IQ than women :)

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

>>while (firstName != 0)
You can't test std::string objects like that while(firstName != "") might work for you here.

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

I don't understand how sending something thru a comm port is going to generate a timer interrupt ? If you have the source code maybe you can just recompile it with a more modern fortran compiler, such as this one.

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

its not necessary to use strtok() to get the filename part. Just call strrchr(). This is a safer way to do it because strtok() requires non-literal strings and the function below doesn't.

char* get_filename(char *path)  {
    char* ptr = strrchr(path,'/');
    if( ptr != NULL)
        ptr++;
    return ptr;
}

>>that seems to me quite strange since filename is declared as char* and my function
>> get_filename(char *path) is declared to return a char*.

Unless you want to do something that you did not post then what you posted should work ok. You can also call that function like this -- assuming it doesn't use strtok() filename = get_filename("/dir1/dir2/file.txt");

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

Well I didn't put it. Admin must have done.

Well, if that was not you then you need to change your password.

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

It doesn't work because the first number in scores.txt (76) is greater than MAX_CODE_SIZE (50). Just delete lines 46-50 and you will get this:

The number of students with scores 0 - 24 are: 9
The number of students with scores 25 - 49 are: 2
The number of students with scores 50 - 74 are: 0
The number of students with scores 75 - 99 are: 5
The number of students with scores 100 - 124 are: 1
The number of students with scores 125 - 149 are: 3
The number of students with scores 150 - 174 are: 5
The number of students with scores 175 - 200 are: 51

Press any key to continue . . .

Any reason to use that list array ? It isn't use for anything

while (infile >> value)
	{
		if (value >= 0 && value < 25)
		    range[0]++;
        else if(value > 24 && value < 50)
            range[1]++;
		else if (value > 49 && value < 75)
			range[2]++;
		else if (value > 74 && value < 100)
			range[3]++;
		else if (value > 99 && value < 125)
			range[4]++;
		else if (value > 124 && value < 150)
			range[5]++;
		else if (value > 149 && value < 175)
			range[6]++;
		else 
			range[7]++;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your coding style is terrible. Don't be afraid to use more white space -- it won't slow down the compile time any and won't take up any more room on your hard drive.

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

line 56: That brace is in the wrong place, move it up one line. As coded now only line 55 is part of that loop on line 54.

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

Here is the formula for calculating the monthly payment

int main(){
    float loanAmt;
    float interestRate;
    int   Months;
    float MonthlyPayment;
    cout << "Enter load amount ...";
    cin >> loanAmt;

    cout << "Enter interest rate (e.g. 6.5) ...";
    cin >> interestRate;

    cout << "Enter number of months ...";
    cin >> Months;
    cin.ignore();

    interestRate /= 1200.0;
    MonthlyPayment = (pow((1.0F + interestRate), Months)) - 1.0F;
    MonthlyPayment = interestRate / MonthlyPayment;
    MonthlyPayment = (interestRate + MonthlyPayment) * loanAmt;
    cout << "Monthly payment is " << MonthlyPayment << "\n";

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

// initialize all elements of the array with some numbers
// of your choice.

That means to set the value of each element of the array to some numbers. There are several ways to do it but the simplest way is like in nick's post above int number[10] = {1,2,3,4,1,6,7,8,9,1}; That means that
number[0] = 1
number[1] = 2
number[3] = 3
number[4] = 4
number[5] = 1
// etc. etc
You can set those values to anything you want -- choice is up to you.

// ask and prompt for key_value so that you can
// type it from the keyboard

display a prompt that tells the user that he/she is to enter a number

cout << "Enter a key value\n";
cin >> key_value;

// create a loop to check each element of the array
// for key_value

Here you have to know about loops. There are a number of tutorials on the net that show you how to code loops. Here is just one of many

In the body of the loop you want to create an if statement to check the value of numbers with key_value. In below code variable i is the loop counter.

if( key_value == numbers[i] )
// do something here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 65: That's a do nothing line, so you might as well delete it.

you need 8 ranges so create an int array with 8 elements so that array[0] represents the quantity of numbers within the first range, array[1] is the quantity of numbers in the second range, etc. etc.

int array[8] = {0}
...
...
if( value >= 0 && value <= 24)
    array[0]++;
else if( value > 24 && value < 50)
   array[1]++;
// etc
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I did not mean to call Initialize() from the constructure because that wouldn't help at all. I had something like this in mind:

class foo
{
public:
    foo() {ptr = 0;}
    void Initialize()
    {
          try
          {
               ptr = new char[255];
          }
          catch(...)
          {
               throw;
           }
    }
   
private:
    char* ptr;
};

int main()
{
     foo obj;
     try
     {
             obj.Initialize();
     }
     catch(...)
     {
          cout << "bad obj\n";
     }
}

If you allow try/catch in the constructor then you have to put the whole class in try/catch which might be undesireable or even not possible

int main()
{
    try
    {
         foo obj;
    }
}

In the above obj can not be used outside the try block.

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

Welcome to DaniWeb

>>I hop it'll be fun
I hop so too :)

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

>>I am pretty sure that you have changed you color scheme in the OS of your choice at some point of time. No?

No.

>>Is aesthetics important?
Probably, but not for a compiler's IDE. You might want to check out some of the other open source compilers to see if they will allow you to change the color schemes.

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

I havent seen anything strange......

Does anyone know what site they got directed to?

Here

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

I guess I should have put a smily face on my statement :) I first noticed it about 0500 GMT but could have happened a little earlier.

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

>>My problem is with kbhit(), is there no way of resetting it, so that I can reuse it?
Yes, extract the character from the keyboard

if( kbdhit() )
   getche(); // or some other function that extracts the key

>>The restrictions though was that I should use "standard" libraries only
There is NOTHING in conio.h that is standard C or C++. And there is no standard way to get one character from the keyboard without <Enter> key too.

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

That is odd, I had no experience of this and have been on and off most of the day lol

That's because you live in the wrong time zone. The term "this morning" doesn't really mean much because for you in UK "this morning" is "last night" where I live. What I saw was a big skull and crossbones then redirected to some other hack site.

Glad the admins got this fixed because I was starting to get DaniWeb withdrawls :)

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

>>i close the file and reopen it to get back to the start of the file (not the best way i know)
Just call rewind() function or fseek()


>>if(strncmp(line,"v",1)== 0)
using strncmp() like that is too time consuming. Since the letter you want is at the beginning of the line just compare the first character if( line[0] == 'v' ) The loop starting on line 43 is incorrect because it will read the last line too many times. It should be coded like this:

while( fgets(line, sizeof(line), infile) )
{

}

>>vertices = malloc(v*5*sizeof(float));
You can't allocate vertices like that because vertices is a 2d array and you are only allocating the first dimension. There are a couple ways you can do this, but if you want to keep the 2d syntax as shown on lines 101-103 then you have to allocate each line separately

int i = 0;
// allocate v number of rows
vertices = malloc( v * sizeof(vertices *)); 
for(i = 0; i < v; i++)
{
   vertices[i] = malloc(5 * sizeof(float));
}

The other way to handle that is to make vertices a single dimension array, but the math on lines 101-103 becomes more complicated.

char *vertices;

vertices = malloc(v*5*sizeof(float));

...
vertices[v*4+0] = x;
vertices[v*4+1] = y;
vertices[v*4+2] = z;
midimatt commented: Great advice thank you very much :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you find this ?

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

The parameter filename is going to contain all the bitmap data? :icon_eek: Then where is the name of the file that function is supposed to write it to ? I'd say you need to redesign the parameter(s) to that function because that is just screwy.

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

At the end of getData() you need to add code to remove the '\n' from the keyboard buffer. Getting numbers (ints, floats, doubles) has the side affect of cin leaving the Enter key '\n' in the keyboard buffer, so the next time a character string needs to be entered cin appears not to do anything. Narue wrote a very good article about how to flush the input stream in this link.

>>Also, how can I prevent input of characters other than numbers in integers, float etc?
You have to accept them as strings and parse the characters to see if there are any non-numeric digits.

Another method is to call cin.peek() to see if there is anything in the keyboard except '\n'.

int x;
    cout << "Enter a number ... ";
    cin >> x;
    if(cin.peek()  != '\n')
        cout << "bad data\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>strcat(screenReturnValue,screenClassName.c_str());

You are attemtping to copy screenClassName into some unallocated memory pointer. screenReturnValue must be allocated before executing this line, and it must be allocated enough memory to hold both screenClassName and "Ptr". To fix it, use the new function to allocate the memory char* screenReturnValue = new char[screenClassName.size() + strlen("Ptr") + 1];

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

I've always read that you should never put code in a constructor that might cause an exception. For example if you need to allocate memory in the contructor then put it in an Initialize() method where the exception can be safely caught and/or thrown.

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

In LinkedList:: insertNodeAtStart() you set the pointers but never set the values of the Hills structure to the value of the parameters to that function. And do the same thing with the other insert function.

void LinkedList:: insertNodeAtStart(int hillsize, int gridref, int distanceFromHome, bool climbed){
    Hills *nextNode;			
    nextNode = new Hills;		
    //nextNode = newInfo;	
    nextNode->hillsize = hillsize;
    nextNode->gridref = gridref;
    nextNode->distanceFromHome = distanceFromHome;
    nextNode->climbed = climbed;

    nextNode->link = head;	
							
    head = nextNode;	

    count++;			
	
    if(last == NULL){	
        last = nextNode;	
    }	

}

Now, the numbers in all the nodes are the same because that's the way they are initialized in main(). If you want them to be different, and I suspect you do, then you have to re-randomize them on each loop iteration

for (int i=0; i<40; i++){
        hillsize = (rand() % 1400) + 3000;
        gridref = (rand() % 100000) +400000;
        list.insertNodeAtStart(hillsize, gridref, 0, true);
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And your point is what ?????

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

see the main() that I posted previously. If the format is ./test U <URL here> I <IP here> then url will be in argv[2] and ip will be in argv[4]. That assumes a space between U and the URL and another space between I and the IP address.

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

Salem already tried to help you in this thread. If you can not understand the code he showed you then what you want to do is way beyond your current level of C knowledge. You probably need to study some tutorials about FILE and associated functions before attempting to continue this program.

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

post current code.

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

I think it would be a lot easier to move the node's data around instead of trying to move the nodes themselves. Moving the nodes means you have to correct all the links. You don't have to do that if you just move the data.

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

Here is a suggestion how to flush the input stream.

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

The most irritating and longest bug to fix was in a MS-DOS 6.X program. I had my own multi-threading kernel and several threads. One thread would set the value of a global integer and another thread would read it. One of the threads (foreground screen) would occationally lock up and would not allow the operator to do anything. It took me about 36 hours straight to figure out that I needed to add some sort of thread synchronization.

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

memcpy(&myStruct, theMessage, sizeof(theMessage));

This still does not put the correct values back into the struct. Any other suggestions?

My post was just a tad bit wrong -- the size of any pointer is on 4 on all 32-bit compilers. What you want is the size of the structure

memcpy(&myStruct, theMessage, sizeof(myStruct));

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

Oooh - what's the size of a ptr AD ;)

duhhhh! :icon_redface:

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

>>If someone could possibly do the exercise and run my through it, i would be really grateful.

I'm sure you would be gradeful. I'll be grateful too if you deposite $10,000.00 USD in my PayPal account. After you do that then I'll gladly email you the program.

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

>>&theMessage
That make it a pointer to a pointer. You don't need the & symbol because theMessage is already a pointer memcpy(&myStruct, theMessage, sizeof(theMessage));

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

Do u mean reading from a file or standard input that is keyboard
If it is standard input u can try
gotoxy (x,y) function

Only if his compiler supports that function. That is a TurboC/TurboC++ function only. No other compiler I know of has that function, but then I don't know every compiler in the world either :)

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

>>Last edited by Good Bye
Yes you did put it. I just don't understand it.

Sorry, but I can't answer you original question.

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

>>is there anyway i can do that without using file handling
Its not all that difficult.

FILE *fp = fopen("filename","r");
unsigned int curpos = fetll(fp);

// go back to previous line
fseek(fp,curpos,SEEK_SET);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to be able to scroll backwards in the file then you need to keep track of the beginning of each line. call ftell() to get the current byte location, then after reading the next line just call seek() with the location that was returned by ftell(). If you want to go back to any random line number at any time then you will want to keep an int array of the return value of ftell().

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

why use one of the dos commands? you can unhide them with windows explorer. Just select view options and check the box to show all files.

But if you insist -- type <c:\ help atrtrib>

D:\Users\AncientDragon>help attrib
Displays or changes file attributes.

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]
[drive:][path][filename] [/S [/D] [/L]]

+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
I Not content indexed file attribute.
[drive:][path][filename]
Specifies a file or files for attrib to process.
/S Processes matching files in the current folder
and all subfolders.
/D Processes folders as well.
/L Work on the attributes of the Symbolic Link versus
the target of the Symbolic Link