nucleon 114 Posting Pro in Training

sid> But what annoyed me really was the reply of Nucleon.

Sorry if I made you cry, sid, but if my post imitating your style annoyed you, imagine how your original post felt to the OP. Are you getting it now? Do you see the point?

narue> boyscout

Actually, since I don't believe in invisible people (hence the "atheist atom" symbol), I can't be a boyscout! (BTW, my opinion of Narue is very high. I think she's great. And, as you'll see, I'm not just sucking up.)

AD> Enough of the personal insults. The next one will get a nasty infraction.

That is absolutely ridiculous! Moderators' time is better spent telling people not to tell lies. And what about sid's original personal insults to the OP? Of course, that's okay! No reprimands for sid! He's just the greatest! Why don't you give him yet more rep? Obviously he's the kind of person that Daniweb wants!

To all:

In my opinion, someone who helps others should have three qualities:
1. Know the subject (and their own limitations).
2. Explain things clearly (and carefully read what others say).
3. Be nice. (Why not?)

Number 1 is straightforward. Programming is not an arcane art but an engineering discipline. A major design criterion in any programming language is ease and practicality of use. Knowing how to program doesn't make you a genius, no matter what your mommy says. ("Oh siddy, my little genius!")

William Hemsworth commented: Cya +9
nucleon 114 Posting Pro in Training

sid> Just check what would happened if delete would reset the pointer to zero:

Nothing would happen! Are you a mindless idiot? Did your brain fall out? Did you replace it with a turd you found on the ground? delete does nothing if it's passed a zero pointer! Moron!

I mean, how stupid would you have to be to think that the OP's question was about the designers of C++ being idiots? Answer: a complete and total moron, i.e., siddhantes!!! The OP's question was about the REASONING (something sid cannot comprehend) of the designers.

To the OP: Don't worry about the "sidiot," as we shall call him. He has serious personality problems. Just ignore anything he says. Everybody else does!

(P.S. The tone of the above is entirely contingent on the sidiot's original tone.)

MrSpigot commented: Ha! Got the tone just right! +1
nucleon 114 Posting Pro in Training

There WAS a problem in reading in the data. I don't know if I did it or you, but the extra strtok (to get rid of the letters A, B, C in the data) needs to be inside the loop. So change the code as follows:

if( strcmp( pch, "MESH_FACE" ) == 0)
		{
			int i, f;
			f = atoi( strtok( NULL, delim ));
			for( i = 0; i < 3; ++i )
			{
				strtok( NULL, delim );
				curObj->facets[f][i] = atoi( strtok ( NULL, delim ));
			}
		}
jephthah commented: man, you really slugged this one out. truly a herculean effort. +8
nucleon 114 Posting Pro in Training

You define a buffer called found_key to hold each key as it is read. It has a length of MAX_KEYNAME_CHARLENGTH (defined, suspiciously, as 20).

If you are sure your keys will never be more than 19 characters long (leaving space for a terminating null), then this is okay, except for one thing: you are also reading values into this same variable as if they were keys! You need to skip the value of keys your not interested in so that you don't read them into found_key and possibly overrunning the buffer or even misinterpretting the value as a key.

Basically you'll have to skip values in exactly the way you do when you want to read them, except you won't be storing them.

nucleon 114 Posting Pro in Training

Please change your data structure and file-handling as I asked above and repost your code. I had asked you some questions, too.

nucleon 114 Posting Pro in Training

Basically you just say "start a new thread of execution here". It shares the same address space as your main (or original) line of execution, which can be handy. How about something like this:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <pthread.h>


void*
KeyboardThread (void *unused)
{
    printf ("In keyboard thread\nPress Enter...");
    getchar();
    printf ("Exiting keyboard thread\n:);
    return NULL; /* Or pthread_exit(NULL) */
}


pthread_t
StartKeyboardThread (void)
{
    pthread_t thread;
    if (pthread_create (&thread,        /* Thread id */
                        NULL,           /* Default attributes */
                        KeyboardThread, /* Thread start routine */
                        NULL)           /* Arg to start routine */
            != 0)
    {
        perror ("StartKeyboardThread");
        exit (-1);
    }
    return thread;
}


int
main (void)
{
    /* To start it */
    pthread_t thread = StartKeyboardThread();

    /* And when you want to kill it */
    pthread_cancel (thread);

    return 0;
}
JimD C++ Newb commented: Great idea and easy to understand +1
nucleon 114 Posting Pro in Training

I saw that no one had responded. The reason I had not responded was because I was "sick of trees". That can happen, you know. Maybe everyone else was sick of trees too. And it was a fair amount of code. And it was the weekend.

I'll take a look at the new stuff when you post it.

nucleon 114 Posting Pro in Training

> yeah, that was really abrasive

Nah, not really. I just had to get used to your style. The fact is that my avatar should be a foot in a mouth.

jephthah commented: mine too. without a doubt. +6
nucleon 114 Posting Pro in Training

You need to use typename. for (typename vector<T>::iterator it = x.begin(); it != x.end(); it++) {

nucleon 114 Posting Pro in Training

You find the = sign just like you found the # sign. Like this: posEqual = search.find("="); If posEqual is equal to string::npos, there was no = sign. Maybe skip that line (and print an error msg).

If posEqual is equal to line.size() - 1 then the = sign is at the very end of the string, which is a special case. Basically the value is a null string, or maybe you consider this to be an error.

If posEqual < line.size() - 1 then

value = line.substr(posEqual + 1, string::npos);

You may wish to trim spaces from before and after the value thus retrieved.

kelechi96 commented: THANKS ! +1
nucleon 114 Posting Pro in Training

This is old school indeed:

int set_keysig (s, ks, init)
  char s[];
  struct KEYSTR *ks;
  int init;
{
   /* function body */
}

Should be updated to:

int set_keysig (char s[], struct KEYSTR *ks, int init)
{
   /* function body */
}

Other than that (and the missing stdio.h header and the fact that you're not returning anything), your posted code has no errors. The lowercasing code should set all but the first character of each word to lowercase. (This is assuming that the "working code" really does "work" ... which seems unlikely given your results.)

Aia commented: Thank you for correcting me. +15
nucleon 114 Posting Pro in Training

You shouldn't really "BUMP" a post. At least pretend to ask another question!

regex is something you can look up yourself, but it is not necessary for your problem. Here's an example of parsing a simple config file:

/* File config.txt:
num = 123
str = hello
flt = 12.2
*/

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

struct Config {
    int    num;
    string str;
    double flt;
};

void loadConfig(Config& config) {
    ifstream fin("config.txt");
    string line;
    while (getline(fin, line)) {
        istringstream sin(line.substr(line.find("=") + 1));
        if (line.find("num") != -1)
            sin >> config.num;
        else if (line.find("str") != -1)
            sin >> config.str;
        else if (line.find("flt") != -1)
            sin >> config.flt;
    }
}

int main() {
    Config config;
    loadConfig(config);
    cout << config.num << '\n';
    cout << config.str << '\n';
    cout << config.flt << '\n';
}
nucleon 114 Posting Pro in Training

>You normally don't need the ignore( ) between two input
>statements of the same type.

Or when the getline() is before the cin>>.

hurbano commented: thanks for the help +1
nucleon 114 Posting Pro in Training

"Please criticize my code." My favorite question! :)

The biggest problem is that your variable names are too long. "Descriptive" does not mean "long". Here are some better names:

mathematicalOperation   expr       (or expression, if you must)
operatorSign            oper       (or operation)
getFirstDigitIndex      iDigit
operatorSignIndex       iSign
firstNumber             strNum1    notice that these go nicely
secondNumber            strNum2    with the names num1 and num2

Here are the structural changes I would make:

int main() {
    string expr;
    float num1, num2;
    char oper;
    while (1) {
        cout << "Enter an expression (-1 to exit)\n";
        cin >> expr;
        if (expr == "-1") break;
        int iDigit = ...;
        int iSign = ...;
        if (iSign == -1) {
            cout << "No operator found.\n";
            continue;
        }
        // etc.
    }
}

Get rid of the "SEE YOU LATER" at the end. (Why do beginners always do that?)

Do not put copyright notices in simple code like this (or anything you write for the next four years).

tux4life commented: Nice advices to the OP ! :) +1
nucleon 114 Posting Pro in Training

The full-cookie solution would be to use conditional compilation to implement code for each platform. Here is an MSDN page describing the functions in conio.h. Remember that you can simply open these headers up and look at them to see what's in them.

jephthah commented: yeah, that's it. +5
nucleon 114 Posting Pro in Training

time's parameter is an alternate return path. If you pass in NULL (or 0) it is ignored. Otherwise, you must pass the address of a time_t object which will be filled with the time.

vmanes commented: Good clear answer! +8
nucleon 114 Posting Pro in Training

SeeTheLite: You're either thinking of protected or friend, but not virtual.

nucleon 114 Posting Pro in Training

(Assuming you're not allowed to use std::list...)
It can be tricky swapping elements in a singly-liked list. Make diagrams so you can see what's needed. You'll probably need extra pointers to remember the previous elements of the two pointers with which you're traversing the list. Also, after you swap two elements, you will have to swap the contents of variables temp1 and temp2 to keep your loop on track.

JAGgededgeOB172 commented: Thank you! +1
nucleon 114 Posting Pro in Training

This is a straightforward program to write with basic WinAPI functions. No MFC (that would be a waste of time unless you know it already) and certainly no OpenGL!
You can either use GDI or the newerGDI+.

NicAx64 commented: GDI and GDI+ now I just reading some tutorial about it. Just started ! +1
nucleon 114 Posting Pro in Training

This deactivates the close option. Remember that you'll have to catch ctrl-C too.

#define _WIN32_WINNT 0x0500
#include <windows.h>
int main() {
  HWND hwnd = GetConsoleWindow();
  HMENU hmenu = GetSystemMenu (hwnd, FALSE);
  HINSTANCE hinstance =
    (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE);
  while (DeleteMenu (hmenu, 0, MF_BYPOSITION))
      ;
  system ("pause");
}
Ancient Dragon commented: Very Good :) :) +36
nucleon 114 Posting Pro in Training

Here's a function that uses a set to remove duplicates from a vector without changing the order of elements:

void remove_dups (vector<string>& v) {
    set<string> s;
    pair<set<string>::iterator, bool> result;

    for (vector<string>::iterator i = v.begin(); i < v.end(); ++i) {

        result = s.insert(*i);

        if (!result.second) {
            v.erase(i);
            --i;  // adjust iterator
        }
    }
}

I'm not sure if the --i can blow up (although note that the first element will never be erased because it definitely will not be in the set).

robotnixon commented: thanks for the help +2
nucleon 114 Posting Pro in Training

This seems to follow your solution but gives me a "multiple definition of void Output<unsigned int>(...)".

// main.h
#include "output.h"

int main () {
    std::vector <unsigned int> v;
    v.push_back (3);
    Output (v);
    return 0;
}
// output.h
#include <vector>
#include <iostream>

template <typename T>
void Output(std::vector<T> &V) {
	std::cout << "\nother\n-------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}
// output.cpp
#include "output.h"

template <>
void Output<double>(std::vector<double> &V) {
	std::cout << "\ndouble\n--------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}

template <>
void Output<unsigned int>(std::vector<unsigned int> &V) {
	std::cout << "\nunsigned int\n------------\n";
	for (int i = 0; i < V.size(); i++)
		std::cout << V[i] << std::endl;
}
StuXYZ commented: Template issue/well spotted. +5
nucleon 114 Posting Pro in Training

I think it's just the X in your input file (should be a 1 maybe?). Your expected output is unexpectedly short, having only nine members.

nucleon 114 Posting Pro in Training

Solved it! (About two seconds after my last post.)
The problem is in this line: return (static_cast<int>(h) % NUM_BUCKETS); You must remove the cast to int, since that may give you a negative number and therefore the mod will return a negative number, giving you an array subscripting error.

fusi0n423 commented: Great help this was really stumping me. +1
death_oclock commented: Nice effort, clever solution, very helpful! +4
nucleon 114 Posting Pro in Training
char buffer[100];
ifstream f;

f.open ("pic.bmp", ios::binary);

// skip header
f.read (buffer, 54);

// read 8 bytes into buffer
f.read (buffer, 8);
weasel7711 commented: Thank you +2
nucleon 114 Posting Pro in Training

It's saying that you can't delete the original "b" anymore because you've lost it's address by assigning a to b, which overwrites the previous address that b was holding. So the last line frees the original a, since b now points to a.

nucleon 114 Posting Pro in Training

Also note that you have to use radians (not degrees) for your angles, so pass = 2 * M_PI / vertex (M_PI is in math.h) .

Alex_ commented: Thank you for telling me about radians! +1
nucleon 114 Posting Pro in Training

Extraneous semicolons are fouling up your logic. Remove them.

else (trump == "S" || trump == "H"|| trump == "A"
            || trump == "D");{ //Won Enough
        score= 30*(numTricks-6);
    }
    if (trump=="NT");{
        score=20*((numTricks-6)+(10));
    }
StuXYZ commented: well spotted +5