tux4life 2,072 Postaholic
else if(operator=='-')
{
    int result = a + b;
}

Dear arshad take a look at your code:

else if(operator=='-')
{
    int result = a [B]+[/B] b;
}

that has to be

else if(operator=='-')
{
    int result = a [B]-[/B] b;
}
tux4life 2,072 Postaholic

or use if statements to solve the variable like...

if(operator=='+')
{

int result = a + b;

}
else if(operator=='-')
{
int result = a + b;

}

Actually I see a better way: use the switch statement for that purpose (As I already mentioned in one of my previous posts)

switch(sign)
{
case '+':
    /* Your code for addition here */
    break;
case '-':
    /* Your code for subtraction here */
    break;
case '*':
    /* Your code for multiplication here */
    break;
case '/':
    /* Your code for division here */
    break;
default:
    cout << "Unknown operator\n";
}
tux4life 2,072 Postaholic

> A simple voice chat program is just a program which sends sound over a network from one side to another side so I guess you'll probably need at least two things:
>>> A network library
>>> A library which deals with sound

tux4life 2,072 Postaholic

To release the allocated memory (of your featlist ):

for(int i = 0; i < len; i++)
     delete[]  ptr[i];

So, no more memory leaks :P

tux4life 2,072 Postaholic

> The function cIndex isn't always returning a value:

int cIndex(char *x,char **featlist,int len)
{
	int i;
	for(i=0;i<len;i++)
            if(strcmp(x,featlist[i])==0)
	        return i;
        /* So what happens when featlist[i] and x aren't equal ? */
        /* You should add a return code to check whether they were equal or not */
        /* Let's say if they weren't equal you return -1 for example */
}

> Your code compiled and ran fine for me (what OS and compiler are you using?)

> Running your code gave me the following output: -7;-7; , is that correct? (I'm using the same file contents for featFile and trainFile as you provided)

> I can't seem to find any place in your code where you're deallocating the assigned memory to featlist , that's a serious memory leak :) ...

tux4life 2,072 Postaholic

Sweet, but sadly im running Linux so i dont think i can view the XPS files.

If you scroll the page a bit down you'll see there's also a PDF version of that ebook available :) ...

tux4life 2,072 Postaholic

> Try ofstream fileOut(P.c_str()); instead of ofstream fileOut(P); :) ...

> ofstream requires the filename to be passed as a const char* , the c_str() method from the string class will convert the string which contains the filename to a const char* and return it (the string itself remains intact) ...

tux4life 2,072 Postaholic

To calculate pi it might be useful to have a high-precision float available where you can store your calculation in, apfloat is really a nice one :) ...

That's why I mentioned it :P

tux4life 2,072 Postaholic

Instead of cin>>name you could use getline(cin, name); to get the first name and the surname :) ...

siddhant3s commented: It took you 5 hours to come up what had been already said ! -1
tux4life 2,072 Postaholic

C++ Beginners Guide (from Herb Schildt), you can get a free ebook copy at Microsoft's site: http://msdn.microsoft.com/en-us/beginner/cc305129.aspx :) ...

tux4life 2,072 Postaholic

> The Complete Reference: C++ from Herb Schildt (1)
> C++ Black Book from Steven Holzner (2)

I'm not good in reviews, but I'll try to give some comments :):
(1) Herb explains everything very clearly and in an understandable way + very detailed explanations, very good examples used in the book and it covers the whole C++ syntax :) ...
(2) This book is also a good one but sometimes it becomes difficult to understand and are there too few examples to demonstrate such an advanced topic :) but to learn to basics it's just a great book, it also covers the whole C++ syntax in detail and might be especially very useful as a reference :) ...
(Both books are written by professional C++ programmers)

> Edit:: C++ Beginner's Guide is also a very nice one (you can get a free legal ebook copy here)

tux4life 2,072 Postaholic

It's not Hensworth but Hemsworth :) ...

tux4life 2,072 Postaholic

Implicitly you can say that it's possible using the work-around Ancient Dragon provided you with :) ...

tux4life 2,072 Postaholic

I don't get that, do you mean the following: Is it possible to call a certain function using two different names ?
e.g:

int a = 5, b = 6;

//makeSum and addition do exactly the same

int c = makeSum(a,b);
int d = addition(a,b);

Do you mean something like this?

tux4life 2,072 Postaholic

> If you're using .NET framework: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx
> This may be more useful to you :) ...

tux4life 2,072 Postaholic

:D I did change it though...

Change

if ( !inData )
{
     cout << "Error in opening file" << endl;
}

to

if ( !inData )
{
     cout << "Error in opening file" << endl;
     return -1;
}
tux4life 2,072 Postaholic

Oh ... I meant that the program runs but displays the error message, "Error in opening file." Howcome? I got it to work, moving it to main.

I've already explained that in one of my previous posts :) ...

tux4life 2,072 Postaholic

Because one reads and one writes? Hahahaha

Of course :), but I asked why you SEPERATED these from your function, why not implement them directly in your function ?

tux4life 2,072 Postaholic

EDIT: It's still giving an error message, even with braces... What now?

You must have done something wrong as your program compiles and runs fine with me :) ...

tux4life 2,072 Postaholic

Why are you using two separate functions read and write then ?

tux4life 2,072 Postaholic

> int findRows( string line ) : Why are you passing a string as argument, you can also declare a variable inside your function instead ...

> return 0; : I would return -1, as a file can also contain 0 lines :) ...

>There's some unreachable code in your function:

if ( !inData )
        cout << "Error in opening file" << endl;;
        return 0; // this doesn't belong to the if statement (it will always execute)

change it to

if ( !inData )
{
        cout << "Error in opening file" << endl;;
        return 0;
}

(if you want to execute more than one function when an expression in an if-statement is true, you should always use a compound statement ( {} ) ...
Your program should work now :) ...

Ancient Dragon commented: You are always very helpful :) +36
tux4life 2,072 Postaholic

Did you try searching google (e.g: typeid , c++ rtti )?

tux4life 2,072 Postaholic

And what's the result ?
Did it work ?

tux4life 2,072 Postaholic

To calculate pi it might be useful to have a high-precision float available where you can store your calculation in, apfloat is really a nice one :) ...

tux4life 2,072 Postaholic

*Deleting a pointer twice is an udefined behaviour too.

Now is just the question left: To prevent deleting a pointer twice: how do we know a pointer has already been deleted :P ?
(I would solve that by implementing a new pointer type, but what's your vision on this?)

tux4life 2,072 Postaholic

I think you'll need RunTime Type Identification (RTTI) for that purpose ...

tux4life 2,072 Postaholic

Please post using code tags :) ...
> Change mymembers m[3] = {(20,22),(21,33),(45,44)}; (in your main)
to mymembers m[3] = {mymembers(20,22),mymembers(21,33),mymembers(45,44)}; > Edit:: Look at this ...

tux4life 2,072 Postaholic

tux4life - does this pass the grammar check ;)

I don't know as I'm not a "native speaker" :P ...

tux4life 2,072 Postaholic

and you are reading the '+' sign in character form yo cannot perform any operations on it!.

And what's this?

char sign = '+';
int n1 = 5, n2 = 7, result;
if(sign == '+') result = n1 + n2; // will compile :)

Comparing a variable to another one, isn't that an operation?
BTW, Reading the expression as a whole line isn't very useful here as the expressions are always like a+b , a-b , a*b , a/d ...

To the OP:
> When performing the division it might be useful to check first whether the second operand is a zero ...
> If you're reading the line which contains the expression using getline , it might be useful to create a simple SkipSpaces function which skips over the spaces, so you can perform operations like this: a *b or a -__________b (where '_' is a space) or ... instead of only a+b , etc ...

tux4life 2,072 Postaholic

another way to solve this problem is to read the intergers in integers!

That's actually what he was doing right now :) ...

tux4life 2,072 Postaholic

Yeah, siddhantes is right (look at the Bjarne Stroustrup's page) !
It isn't because it seems to work it's actually working (that's just C++) !

tux4life 2,072 Postaholic

I hope the OP does get it, but I'm afraid I don't.

Didn't you mean: but I'm afraid he doesn't ?

tux4life 2,072 Postaholic

Read this and this (I think the first link is your best bet) ...

tux4life 2,072 Postaholic

In this bold part you say the next read value will be interpreted as an integer but where is the next read value, isnt there only one read value in this code (sentence) ?

Thanks a lot!

sentence is the string where the sscanf function reads from, in the string "Rudolph is 12 years old" you've 4 words and 1 number, but for the sscanf function these are just 5 values:

1) Rudolph
2) is
3) 12
4) years
5) old

Edit:: "%s %*s %d" says that the first value is a string (%s), the second value is also a string (but sscanf has to ignore this one) and the third value is a number (an integer (%d)))

Edit:: sscanf (sentence,"%s %*s %d", str , &i ); the higlighted parts tell the sscanf function where to store the read and non-ignored parts of the string sentence ...

tux4life 2,072 Postaholic

can you tell me why I would ignore the read value with this " %*s"? I understood other parts, thank you very much...

That's just the function's syntax: the '*'-sign indicates that the function has to ignore the following value (not you :P) ...

Edit:: You can find more information on this in the table on this page ...

tux4life 2,072 Postaholic

>> num1 sign num2 = answer; is not a valid C++ expression

>> e.g.: (this code will never work)

char sign = '+';
int n1 = 5, n2 = 7, result;
result = n1 sign n2; // won't compile

>> This code is the correct way to do this:

char sign = '+';
int n1 = 5, n2 = 7, result;
if(sign == '+') result = n1 + n2; // will compile :)
tux4life 2,072 Postaholic

You don't have to use cin.get for that purpose, just do something like this: infile >> [I]yourvariable[/I]; :) ...

Edit:: num1 sign num2 = answer; will never work (even if you had typed num1 + num2 = answer; it won't work) ...
You'll have to use something like a switch statement to parse the expression:

switch(sign)
{
case '+':
    /* Your code for addition here */
    break;
case '-':
    /* Your code for subtraction here */
    break;
case '*':
    /* Your code for multiplication here */
    break;
case '/':
    /* Your code for division here */
    break;
default:
    cout << "Unknown operator\n";
}
tux4life 2,072 Postaholic

Yeah, if you really want a feature like that you might have to implement it yourself: Create a new pointer datatype and overload the delete operator for it in such a way that the pointer is always set to NULL after releasing the allocated memory :) ...

tux4life 2,072 Postaholic

what do "i" variable and str[20] array do in this function?

Edit:: > The i and str[20] variables are declared to store the result of the sscanf function

> As already mentioned (or not) sscanf reads from a buffer (the str[20] string/array)

> sscanf is used to read "things" from a string and put them in variables ...

> I assume you aren't understanding the following line: sscanf (sentence,"%s %*s %d",str,&i); >> sentence is the string where the sscanf function reads from, after the first comma you see the following: "%s %*s %d" where %s tells the sscanf function that the following part it will read will be a string, %*s means that the function will ignore the read value and %d tells the function the next read "thing" should be interpreted as an integer ...

>>After "%s %*s %d" you encounter the following: ,str,&i which tells the function where to put the read values (the first read value will be put in a string called str, the second read value will be ignored (note the asterisk *), and the third read value will be stored in an integer variable ...

>>> Hope this helps :) !

tux4life 2,072 Postaholic

After deleting you could simply set your pointer manually to NULL:

int *ptr = new int;
delete ptr;
ptr = 0;

By the way, why should delete reset the pointer to NULL , C++ is a programmer's language and those programmers want to control every single aspect of the language, this brings with it that you'll have to do some things manually, but in this case, it's only one single line of code extra :) ...

tux4life 2,072 Postaholic

Take a look at:
> http://www.cplusplus.com/reference/clibrary/cstdio/sscanf/
or
> http://www.cppreference.com/wiki/c/io/scanf (sscanf is just like scanf, with the difference that the input is read from the buffer) ...

tux4life 2,072 Postaholic

The program does not interact with the internet.

But i'm having problems, with reading from the csv file, put the line's into a vector and searching and combining username and password.

Does the account database have to be in a CSV-file ?

Edt:: Take a look at: http://www.dreamincode.net/code/snippet1316.htm

tux4life 2,072 Postaholic

Alas, that's actually one of my problems, is that I don't have visual studio on my current machine, which makes it a lot harder to debug this. :(

You can get a free express edition of Visual Studio here :) ...

tux4life 2,072 Postaholic

Can you please provide me with some more information about what your program actually does ?

tux4life 2,072 Postaholic

According to your code you want to convert a value (integer) to a hexadecimal number, why don't you just declare value as a string and use stringstreams to convert the number to a hexadecimal number like here: http://www.daniweb.com/code/snippet1162.html :) ...

tux4life 2,072 Postaholic

You could also use a C++ library called 'apfloat' it's freely available here ...

tux4life 2,072 Postaholic

I wanna work with some 40 digit numbers here. (I know I'm using int up there)

Try the apfloat C++ library: http://www.apfloat.org/apfloat/ ...

tux4life 2,072 Postaholic

Does anyone have a sample code, for User Authentication system with the basic functions, login/registration?

You could simply write something like that yourself, but as you're mentioning 'registration' I've to following question: has to program to interact with the internet to register, or is registering not explicitly required ?

tux4life 2,072 Postaholic

Maybe you should read a C tutorial first, it's only a suggestion, but I think it will help you a lot :) ...

tux4life 2,072 Postaholic

Strange the following is working: final += hex_string; As far as I know hex_string is a pointer and final is a string, but I don't know whether the + operator is overloaded for data of type char* ...