Banfa 597 Posting Pro Featured Poster

I know why (I think), IIRC the linker does a single pass of the files, when you have lib/ft/libmbusmaster.a before client.o it looks in lib/ft/libmbusmaster.a and because it hasn't seen anything yet that uses it discards all of it. Then it tries to link client.o and finds lots of unresolved externals.

The other way round in looks in client.o first, finds lots of unresolved externals then looks in lib/ft/libmbusmaster.a and resolves them.

Banfa 597 Posting Pro Featured Poster

Instead of lib/ft/libmbusmaster.a on the g++ command line try -llib/ft/libmbusmaster.a or -l lib/ft/libmbusmaster.a

Banfa 597 Posting Pro Featured Poster

Sorry that's a typo on my part should have read

"you can't directly compare C style string using =="

Banfa 597 Posting Pro Featured Poster

That is right you can directly compare C style string using ==. You need to use the library function strcmp

Banfa 597 Posting Pro Featured Poster

A good TCP/IP (and UDP) primer is Beej's Guide to Network Programming which is downloadable in various formats or available as an actual book.

@kings_mitra Doh you beat me to it :D

Banfa 597 Posting Pro Featured Poster

sscanf is not up to dealling with all those different formats. You would be better off searching the string for // and then checking to see if it is followed by a digit and then if it is using atoi or strtol to convert that to a binary value.

Banfa 597 Posting Pro Featured Poster
main()
{
	void USERF(double *,double *,double);
.
.
}

You can't declare functions-in-functions in C, perhaps in JavaScript or Pascal but not in C/C++. Take that declaration outside main().

Actually you are wrong, you can declare functions inside functions like that. What you can't do is define functions inside other functions like this

int main()
{
	void USERF(double *,double *,double)
	{
	}
.
.
   return 0;
}
nbaztec commented: Really! I didn't know that. Thanks for the info. +1
Banfa 597 Posting Pro Featured Poster

itoa is not an ANSI/ISO standard function and is non-portable, also it converts an integer to a string not a string to an integer.

Try atoi or strtol

Banfa 597 Posting Pro Featured Poster

If you don't get it how did you write it in the first place?

Banfa 597 Posting Pro Featured Poster

Here is your function S_NEWT with the code removed and the relevant parameter highlighted

void S_NEWT(int *n,double *x0,double e,int NMAX,[b]double (*FUNC)()[/b])
{
   <snip>
}

The () at the end of the highlighted parameter represents the parameter list for the function pointer FUNC.

Here is the prototype of your function USERF

void USERF(double *,double *,double);

The parameter list is everything between ( and ). () and (double *,double *,double) are not equivalent, you need to alter the () in your function S_NEWT to match what is in USERF.

This needs to be done both where S_NEWT is declared and defined.

Banfa 597 Posting Pro Featured Poster

Firstly its a warning not an error, the program still compiled and possibly worked. However that said plenty of programmers use the rule of thumb that all warning should be dealt with and the program should compile without warnings.

You have declared S_NEWT as taking a pointer function with no parameters but supplied it with a pointer to a function that takes 3 parameters. Try fixing the prototype of S_NEWT to take account of the 3 parameters in USERF.

Banfa 597 Posting Pro Featured Poster

Was that all the errors? Having the complete text of the error messages would help (unless that's also in Japanese).

I couple of points

main returns int, returning default int without a warning tends to suggest you are using an old compiler.

Using capital letters for you function names is a little unusual, I assumed they were macros at first, however it is not actually wrong.

You do not seem to have declared S_NEWT before trying to call it. That may be having an effect as the compiler will not know what the function prototype is.

Banfa 597 Posting Pro Featured Poster

I am using fstream, so it should include cin and cout. What I learn is that fstream is inherited from iostream,ifstream,ofstream and some other header files so includes the functions of iostream as well.

I took note of your suggestions, thanks for it. I took note of it.

No fstream in <fstream> inherits iostream in <istream>. cin in <iostream> inherits istream in <istream> and cout in <iostream> inherits ostream in <ostream>.

There is no connection in inheritance or filewise between fstream and cin or cout. To use cin or cout you must specifically include iostream.

NOTE: the class iostream is not declared in the header <iostream>

See here

jonsca commented: Excellent clarification +4
nbaztec commented: Nice. +1
Banfa 597 Posting Pro Featured Poster

That is because fstream.h (and all other C++ headers ending .h) is a pre-standardisation header i.e. over a decade old and has been depricated for sometime and I expect MS has taken action and removed it from their IDE/compiler.

use #include <fstream>

Banfa 597 Posting Pro Featured Poster

you have not defined the return types of several of your member functions making the compiler think they are incorrectly named constructors.

Banfa 597 Posting Pro Featured Poster

Nope because map is declared as int map[3][9][10] , map[1][1][1] has type int so map[1][1] must surely be something different.

Do you not get an error similar to
error: invalid conversion from 'int*' to 'int'
when you compile it. Surely that gives you a clue to the type of map[1][1] ?

Banfa 597 Posting Pro Featured Poster

You only have 2 array dimensions, what is the type of location , what is the type of map[location][direction]

Banfa 597 Posting Pro Featured Poster

You have 4 {, every dimension of array requires a { so you have 1 too many.

You inner most array initialisers have 10 entries, but the last dimension of you array has a size of 3. The sizes do not match.

Looking how you have laid out the data I suspect you should have declared int map[3][9][10] or of course fix the initialiser.

Banfa 597 Posting Pro Featured Poster

Line 8, you get an integer, presumably you input either 1 or 2.

But in your case statements you using '1' and '2', these are the characters 1 and 2 and respective have the values 49 and 50 (assuming ASCII) so your 1 and 2 input don't match.

Using the integer values is the correct approach which you have tried. The segmentation fault I assume is caused by something later in your code in the functions get() or getnext().

In case 1 since count is always initialised to 0 it will always call get(), the whole of case 1 can be reduced to a call to get() and the variable count can be discarded.

Banfa 597 Posting Pro Featured Poster

Take it out of students::AddStudent and add it as a static data member of class students.

BTW line 16 is a waste of time, you may as well just change line 4 to class STUDENTS {

Banfa 597 Posting Pro Featured Poster

But my question is for SQ(a+2) >> a+(2*a)+2 ...that means when a=5 the answer is 17.

You could easily follow the same process griswolf already did he left out the - but put it in and you get

-SQ(a+2) == -a+2*a+2 == -a+(2*a)+2 == a+2

Therefore for a=5, -SQ(a+2) == 5

By the way the answer to your second post is its undefined behaviour.

Banfa 597 Posting Pro Featured Poster

Erm, 1020304 and 01020304 are the same number the second one just has a leading 0.

Banfa 597 Posting Pro Featured Poster

No it's there because they try to call them. Generally when grepping if you have the source it is better to grep the source code no the binary library. If you did you would find that the source code attempts to call these functions but they are not defined anywhere.

And that is what "undefined reference to" means, a symbol (class name, function name, variable name) was used by a piece of source code which compiled fine because the symbol was declared, however the symbol was not defined so the linker can not resolve the reference to it.

A quick Google (or your alternative other search engine) on dcoomm will show that it is part of the Sun Performance Library which appears to be a library that Sun distributed with there compiler toolset.

I couldn't actually find a source for the library but on the other hand I did stop looking once I found out what it was.

Banfa 597 Posting Pro Featured Poster

In Eclipse, surely you can set libraries to link to without needing this syntax.

Well yes but it does rather depend on how you have your projects set up in the first place.

Personally I think Eclipse is a bit heavy weight and confusing for a new user and I particularly dislike the way it seems to think it is a separate file system independent of the actual file system.


You might want to try something a little lighter and easier like CodeBlocks

Banfa 597 Posting Pro Featured Poster

Thank you so much for downloading Sparselib and having a look. I did not understand what you meant by .

You have not lost much by not understanding because I was wrong :D

I hadn't noticed that they were using .cc files and my IDE grep was set to only search .h and .cpp

Anyway what davidora is saying (and I think thay are on the right track) is that when you call the build using the makefile SparseLib++\1.7\makefile the result should be that these 3 libraries

libmv.a
libsparse.a
libspblas.a

are created in SparseLib++\1.7\lib

If when you link your application you leave these libraries out (off the linker command line) then you will get unresolved externals similar to what you have got.

The header is NOT the library, the header is just the interface to the library that you compile against. To use the library you also have to link against the binary lib file.

Banfa 597 Posting Pro Featured Poster

Sorry I was getting a little confused.

So you have the undefined reference errors?

I downloaded SparseLib and examined a couple of them

coord_double.h:66: undefined reference to `MV_Vector_int::~MV_Vector_int()'
coord_double.h:66: undefined reference to `MV_Vector_double::~MV_Vector_double()'

Those functions, the destructors on those classes, do not exist. They are defined in the right place but while all the other methods of those classes are also declared in the headers those ones aren't.

I think you are probably going to have to go through and edit the files to implement the missing functions to get this to link.

Either that or find a place that provides specific help on this library.

Banfa 597 Posting Pro Featured Poster

If those headers contain a definition or use of the symbol COMPLEX by placing it before you include the headers you change the headers and by placing it after them you don't.

BTW compiler/linker errors without the lines of code the correspond to are nearly (not quite but nearly) useless.

In the last listing it looks like you are missing a library or object file when you are linking.

Banfa 597 Posting Pro Featured Poster

The compiler probably doesn't crash after entering c because the compiler never requests that you enter c. Presumably you are actually running the program to get to the enter c phase. The program doesn't crash either, it does what you have asked and exits normally (or it does for me but then since this program exhibits undefined behaviour it is impossible to say what is happening for you).

You have the following problems

Line 4: Returning void is an extension that not all compilers support, get in the habit of returning int now.

Line 11: Unnecessarily declare c which is never initialised to anything.

Line 12: Attempt to add a and b and store the result in s before you have obtain values for a and b. Reading uninitialised/unassigned automatic variables is undefined behaviour.

Line 15: you don't scan the input return you typed so it is left in the input buffer, we'll come back to this ...

Line 19: Here where you ask for a character, the system looks at the input buffer which contains a line feed and returns that to you, no extra input is required.

Line 20: Access to the initialised variable c is undefined behaviour also this is not how you check if variable d is equal to the character c. You need to use a character constant (you can Google that).

Aia commented: Good effort. +9
Banfa 597 Posting Pro Featured Poster

As always with programs when you have a problem with your command line arguments put them in quotes -D"COMPLEX=std::complex<double>" I imagine that the command line interpreter is < as the input piping operator.

Banfa 597 Posting Pro Featured Poster

Erm, that is already a 2d array, it is not clear what your problem is.

Banfa 597 Posting Pro Featured Poster

Where and how do you define your original array?

Banfa 597 Posting Pro Featured Poster

You might try having a look on http://www.zilog.com/

and not the the header file is unlikely to be any use without the accompanying binary library.

Banfa 597 Posting Pro Featured Poster

p does not point to any ClsA objects, p points to a pointer to ClsA objects.

A pointer is a built in type and has no constructor or destructor. So no destructor call is required for that delete statement.

Presumably in the code lines 21-22 you have something that does p[0] = new ClsA[10]; and the destructor will be called when you delete this memory delete[] p[0];

Banfa 597 Posting Pro Featured Poster

Hard to tell without seeing the actual output and the desired output.

Banfa 597 Posting Pro Featured Poster

the problem now is how do i remove the duplicate strings from an array. I want to copy strings from array A[] to array B[] without duplicate entries. please somebody suggest a code for this.

AND

how to i detect whether the entries in an array are over without knowing the count as to how many entries exist??

Before you add a string to A[] check all the entries that are already in it to see if any are the same as the one you are about to add and don't add it if any are.

AND

You can't storing the number of used entries in an array is an integral part of being able to use it.

Banfa 597 Posting Pro Featured Poster

" is a special character as it delimits the string. If you want a " in your string you need to escape it using \ so the compiler treats it as a character in the string and not a string delimiter like this "\""

Banfa 597 Posting Pro Featured Poster

That is because \ is the escape character in string literals in C (and C++) so '\t' is a tab character and '\p' is p (I think). To get an actual slash you need '\\'

Banfa 597 Posting Pro Featured Poster

I am not very experienced in programming, but I think you can do this without using any of the functions like atoi(), etc....

You could do but why re-write code that has already been implemented for you in the library? You are just wasting time and effort that could be put into the program logic proper.

Also what you suggest takes no account of white space but most users would be put out if you rejected there input because they happened to put a space before or after the number.

Using stringstream or strtol takes a lot of the hard work out of the job, which isn't to say that some experienced programmers wouldn't go ahead and do it the way you suggest.

Banfa 597 Posting Pro Featured Poster

A fair point and I probably should have pointed out that the C standard library is available in C++.

What I was trying to combat was the tendency of people who have learnt C first to just use the C method they know rather than looking for the C++ way even if they then discard that method as inefficient or for some other valid reason.

I am mildly surprised that using a stringstream is less efficient because those C++ gurus definitely seemed to have made execution efficiency a priority in other areas. On the other hand I have also felt that the C++ stream library lacked the elegance displayed by say the STL containers. The shear amount of code required to output formatted data compared to what you can do with printf is daunting.

Banfa 597 Posting Pro Featured Poster
Banfa 597 Posting Pro Featured Poster

atoi() returns 0 on error. strtol() is the same function but converts it to long int.

If the text length is greater than 1 and the output is 0, that would indicate an error. Unless someone really wanted to put 000 in there or something.

Using stringstream to cast to int will also fail with output of 0 if the characters are not digits. Admittedly, stringstream is the more C++ way to do it.

You have answered your own question atoi does not return 0 on error 0 is returned for a number of reasons so a 0 return does not equate to a definite error.

strtol is not the same function because it returns a pointer to where the conversion finished so you can easily tell if the conversion finished because it reached the end of the string, white space or an invalid character. Also strtol will handle bases other than 10 which atoi wont but that isn't really relevant here.

Using stringstream with fail with the failbit set if the input characters are not digits. You can not use the output value of convert to integer as a test for success because there are no invalid output values.

Banfa 597 Posting Pro Featured Poster

No I mean more like

string line;
int value;
istringstream iss;

getline(cin, line); // Get a ine of input from user
iss.str(line);      // Put it into a stringstream for processing
iss >> value;       // Get an integer value

// At this point you can check the status bits of iss for failure 
// to convert the integer and you can get what is left in the 
// stringstream and see if it contains any additional characters
Banfa 597 Posting Pro Featured Poster

atoi() is unlikely to help because it has no error output, you could use strtol() however neither of those are C++ they are part of the C standard library and C++ provides the same functionality through the use of stringstreams.

Banfa 597 Posting Pro Featured Poster

If they have input only integer data then all there should be is a string of digits.

  1. So get you get a line of input

  2. Extract an integer from it
  3. Verify the rest of the line is blank

If either step 2 fails or the rest of the line is not blank at step 3 then you have an input error.

You can use getline for step 1 and then a stringstream for steps 2 and 3.

Banfa 597 Posting Pro Featured Poster

You shouldn't just output rgValue, it is binary data unless Type has a value of REG_EXPAND_SZ, REG_MULTI_SZ, REG_SZ.

If the value in the registry is really a DWORD then Type should be REG_DWORD and size1 should be 4 on exit. In that case something (non-portable) like DWORD dwValue = *((DWORD*)rgValue); should do the trick. Alternatively just pass a pointer to a DWORD into RegQueryValueEx in the first place if you are sure of the type the key holds.

RTFM: RegQueryValueEx

freemanirl commented: Yes! +0
Banfa 597 Posting Pro Featured Poster

tests and RunExperiment are both members of Experiment so RunExperiment can access tests directly even though tests is private since this only stops access externally to the class.

tests is an array of pointers Test *tests[maxTests] so tests[0] has type Test* so to access the member of Test you would use tests[0]-><Member> .

Banfa 597 Posting Pro Featured Poster

I am not convinced by this solution for instance line 17 can be replaced by

number /= i;
i -= 2;

which seems rather simpler and less wasteful of stack space.

The whole point of recursion, in my opinion is to remove iteration (loops) so way recursive function with a loop in it is suspect.

I think the returns look a little strange for a void function I would either leave the out or if I want explicit returns I would put them on the next line.

Banfa 597 Posting Pro Featured Poster

@coded_hitec I believe the answer to your question is "no" but I would be happy to be corrected.

Banfa 597 Posting Pro Featured Poster

No YOU are wrong, that is not 2 variables at the same address, that is a variable and a reference to the same variable. A reference is not a variable.

You can not have 2 variables at the same address, the standard specifically mandates against this.

You can not change the address of an object once it has been assign by the compiler.


You might be able to achieve what you want by using pointers

int a, c;
int *b = &c;

a = 10;
*b = 3;

// then later

b = &a;
Banfa 597 Posting Pro Featured Poster

You appear to be trying to use TempBuffer to temporarily read a string before storing it. If you are reading a string from a file into a buffer how many dimensions does the buffer need?

When calling fgets it is a really bad idea to give the buffer size as bigger than the size of the buffer you are actually passing a pointer to.

How many line does this file contain? How many times does your code call fgets?

You are not checking the return value of fgets so you will continue trying to process the file even if an error occurs or the program gets to the end of the file.

Is array supposed to be an array of 100 strings or an array of an array of 100 strings (or colloquially are 2 dimensioned array of strings with both dimensions sized as 100)?