rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ok. On Windows, a text newline ('\n') IS a carriage-return+linefeed ('\r\n') combination. You would only need to use the latter representation if you were reading the file from Unix/Linux systems. On Windows, it is still encoded as '\n'. IE, don't sweat it unless you are reading a file from one system type on another and have not passed the file through a filter to convert newlines accordingly, which normally a tool like ftp will do for you if the transfer is specified as text-type. There are also other tools which will convert newlines for you - this is a very common problem.

So, if you execute the function fprintf(outfile, "Hello World.\n"); on Windows, the file will contain a '\r\n' terminator on the line. On Linux/Unix, it would contain only a linefeed ('\n'). Reading back, the same code should work appropriately on either system, making programming applications that is intended to work on both types of systems much easier. Again, problems only occur when you are processing data written on one system type on the other.

And welcome to cross-platform programming and all the little warts you will encounter in that endeavor! :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There is no guarantee that the ack gets back to the sender, as in the lost ack scenario. However, each packet has a sequence # and CRC, so the receiving network stack will keep track, especially if there are missing packets in between the ones it got. If it gets a duplicate, then it will discard the new copy, yet ack that as well so more don't get sent (hopefully). Naks are for packets that were received with a bad CRC. If the connection is really flaky, then it is possible that a duplicate will be received after the original one has been transmitted to the receiving application; however, the stack (driver) will STILL know that the current window has passed by the duplicate packet, and it will ack/discard it.

This is a problem at the network stack level - and not at the application level. I do network programming in high-volume, high-speed environments (multiple thousands of interacting systems world wide with 10 gigabit network connections internally, and multi-gigabit connections to the internet. This is NOT a problem! :-) It is a good school problem, however, which will impact hardware and firmware designers. My suggestion is that you develop a rigorous finite-state-machine representation of how to deal with this situation. I always find that it clarifies such edge cases very nicely.

FWIW, I have implemented a full TCP/IP stack for real-time embedded systems in the past (around 1990), so this is an issue I am intimately familiar with, and that …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Yech! I used to have an AT&T 2Wire as well, and it is an absolute piece of junk. I had them replace it with a Motorola Netopia device - been working for over 4 years now without a hiccup! Anyway, if you go into the configuration web pages for the router, you should be able to change its configuration from router to bridge. Then, just hook your netgear to that, and let it do the routing. I did that with a Linksys router (switched to bridge mode) to good effect. Anyway, it is worth a try. Assuming you are running DSL and not U-verse, it may be easier to just get a DSL modem to hook to the netgear.

A final note. I think you will need to connect a port on the 2Wire to the WAN port on the netgear router for this to work. You may need a patch cable to do that.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Your printArray() functions don't return anything, so there will be no operator << associated with them. Remove the outfile << in main() from lines 32 and 33.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

A crore == 10M, right? lahk == 10K as I recall... :-)

An array of 200M elements (assuming array of pointers pointers) on a 64-bit machine will take 200Mx8 bytes (minimum) of memory, which is 1.6GB. Most systems won't allow you to allocate such sizes on the stack, so you may need to allocate it on the heap with calloc/malloc calls. On some systems, you can allow users to allocate huge stacks, but it really isn't a good idea.

So, can you provide some indication of what you are trying to accomplish? We may be able to provide more relevant advice in how to manage that much memory if we knew.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

How do you think it should be done? This is a C programming question (class exercise I presume), no? Show us how you think it could be solved, and then we will try to help. Just don't ask us to do your work (school or otherwise) for you.

Hint: try casting the hex value to a float, and print the resulting value.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

A GUI has little to do with an operating system. There are currently about two core operating system types:

  • Monolithic kernel
  • Micro kernel

as well as

  • Determinist real time
  • Non-deterministic not real time
  • Non-deterministic soft real time

There may be some that are, at least on the surface, a combination of those first two. Linux is an example of a monolithic kernel. QNX, now the operating system used by Blackberry (RIM) on their new BB-10 devices, is a micro kernel design. MS Windows is a bit of both.

If you want a system that can be used for applications such as fly-by-wire avionics, nuclear power plant controls, high-speed industrial control systems, then you need a deterministic real time operating system. If you are running a workstation, web server, etc, then a non-deterministic not real time system will work just fine. If you need something that can run many industrial systems such as warehouse conveyor systems, then a non-deterministic soft real time system may be the thing. Again, QNX is an example of the first type, Windows an example of the second, and Linux (with RT scheduling enabled) is an example of the third.

There are also variations of how user-space (applications) communicates with the kernel and drivers. For that there is the system call method, ioctl calls (both of which are used by Linux), and then there is the message passing method (used by QNX and some other operating systems). There has been a great deal of debate …

mike_2000_17 commented: Great summary! +13
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Your problem is that your first argument should be then entire command path, and the second an array of argument to pass to the command. IE,

const char* arglist[5] = {"arg1", "arg2", "arg3", "arg4", 0};
if ((err = execv("/usr/bin/cmd", arglist)) == -1)
.
.
.
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Anyway, you posted an excellent question for newbie C/C++ programmers, and an area that a lot get wrong. Keep on trucking! :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Any* is an array of items of type Any (and use const char* in your examples, otherwise most compilers will complain). In effect, it is a pointer to the first element of the array, so that Any++ will point you to the next element in the array.

An array of pointers, such as Any* many[5], points to an array of arrays of Any items. Your example of const char* members[4] = {"Sally", "Alex", "George", "Martha"}; is such.

So, cout << array << endl; will output the line

some stuff

and cout << members[0] << endl; will output the line

Sally

If you do this:

cout << ++array << endl

you get

ome stuff

but if out do this:

cout << ++members << endl

you get

Alex

That is because in the last case, you are moving the pointer to the next member in the array of pointers, and in the previous case you are moving the pointer to the next member in that array of chars. Clear as mud, right! :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What deceptikon said, run FC in a virtual machine. You can download and install VirtualBox (www.virtualbox.org) free on any supported host (WinXP, Win7, Linux, et al) and run just about any x86-based system on it. Some new systems, especially those running Windows 8, are using the secure boot feature of UEFI, which makes installing other operating systems very problematical.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Is this for homework?

I would suspect so. At least they are making a reasonable effort to solve the problem, so helping them (at least as far as pointing out their errors) is not unreasonable, IMHO.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

FM (Farking Magic). :-) On Red Hat (RHEL and Fedora) systems, 32-bit libraries are installed into /usr/lib, and 64-bit ones in /usr/lib64. The system knows when an application is 32-bit or 64-bit and will load the appropriate shared libraries. If your colleague provides an RPM file for installation, then the yum package manager will deal with installing the dependencies for you. If it is in source or other (binary) form, then you will probably need to install the dependencies (32-bit versions) manually (use yum to do that where possible).

As for compilers, it doesn't matter. The 64-bit version of the gcc compilers will handle 32-bit code just fine.

Since you installed OpenCV via git (source code), if there wasn't a configure script (which should deal with 32-bit vs. 64-bit issues when generating the Makefiles), then you may have needed to modify the Makefile(s) to install the libraries into /usr/lib64, or /usr/local/lib64. I've run into this issue in the past for packages that were not configured to handle Red Hat or Suse distributions properly.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

JorgeM is correct, except that normally it would be 253 IP's since the router gateway address will take at least one (usually 1 or 254) as 0 and 255 are special cases and aren't used for node id's.

Here is a good Wikipedia article on the subject: http://en.wikipedia.org/wiki/IPv4

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Use virtual machines to install/test new kernels first? I don't think that a 2.6.21 kernel will work with FC14 as there are SERIOUS deltas between the 2.6.2x and 2.6.3x kernels which require different user-side application versions to run. IE, won't work unless you also downgrade just about everything else on the system!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

VMware or VirtualBox - they are basically the same in that they allow you to run other operating systems in virtual machines on a single host. Myself, I like VirtualBox (open source and free) and use it on both Linux and Windows hosts. For my personal work, I run VBox on a Scientific Linux (RHEL clone) host, and for work I run VBox on a Windows 7 host. Not much difference that I can tell.

As Mike2k said, cross-platform development should be done on the system you are most comfortable with, and then recompiled and tested on the target platforms. I've been doing this for well over 20 years. Developing code that runs identially on Windows and Linux/Unix however means that you need to develop some good conditional macros that will "tag" classes and functions appropriately for Windows, but not for Linux/Unix (import/export etc). Also, if you want to build stuff that will conform to COM and such for Windows then there are more issues you will need to resolve.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The telnet protocol has a complete conversation between client and server on startup. When you connect, it (the server) sends you queries about what your (the client) capabilites are, and you need to catch them and reply accordingly. That is so the server knows what to do when you send it data. All of this goes on before you get the login prompt. If you don't respond to them, then eventually it will time you out and terminate your connection. Since I have in the past implemented the complete telnet protocol (both client and server) for a real-time operating system (back around 1990), I can assure you that this is not trivial - not difficult, but not easy. First, you need to find documentation for the protocol on the internet (or pay big $$ to purchase the DDN white books, courtesy of the US Department of Defense), and then you need to implement the client side of the conversation. In truth, there isn't much you need to be able to do, but handling the "can you" queries is essential.

Have fun! :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Good question. Yes, you would have to iterate the array and call free on each element that was malloc'd. However, if this is the extent of your program, you really don't need to as the system will clear the heap for you on exit of the program.

tofumaker commented: thanks alot for the help, solved a problem i was struggling with for a few hours +0
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What mike_2k said, but understand that for an application to use the libraries you installed in /usr/local/lib, you will need to update the LD_LIBRARY_PATH environment variable to search there. IE, in your .bash_profile add this line:

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib"

The reason for the {} around LD_LIBRARY_PATH is because you are using it recursively to redefine the LD_LIBRARY_PATH environment variable, so just using $LD_LIBRARY_PATH is not safe.

If you want libraries in /usr/local/lib to be found first, then switch the LD_LIBRARY_PATH and /usr/local/lib around, as in

export LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Try this:

    int x = 0;
    int buf[4];
    int* array[5];
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            buf[j] = x++;
        }
        array[i] = (int*)malloc(sizeof(buf));
        memcpy((void*)array[i], (void*)buf, sizeof(buf));
    }

    for (int i = 0; i < 5; i++)
    {
        int* temp = array[i];
        for (int j = 0; j < 4; j++)
        {
            printf("%d\n", temp[j]);
        }
    }

Bear in mind that some older compilers will object to the second outside for(int i = 0; i < 5; i++) as they don't properly scope the variable declared in the for() loop to just that loop.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Start by visiting Wikipedia and other web resources and doing some research on the subject.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

As cereal mentions, to do this you need to encrypt the drive. There are a number of tools to do this, including TruCrypt: http://www.truecrypt.org/

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What JorgeM said notwithstanding (good advice/comments), the randomness indicates to me that this is likely a hardware problem, such as overheating of system components. If a hard shutdown (hold down power button until system stops), wait (10-15 minues), and then a restart works (for awhile), then I think that will be pretty indicative of the case for a hardware problem - send it in for service.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

RAR files have nothing to do with Java. They are multi-part archives that can easily be rejoined to create the original file, or file set. There are a number of free applications that can generate or extract rar sets, both for Windows and Linux; however, they have to license the code from Alexander Roshal, so they really aren't open source (as in FOSS). Here is the wikipedia article with a lot of information that may help: http://en.wikipedia.org/wiki/RAR

As far as I know, if you want to create a Java implementation, you will have to license and obtain the code from Roshal.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Try a Google search on the terms "DSW" and "Algorithm". Here is a good link to understanding the application of DSW to balancing a "vine" structure - ie, a degenerate binary tree.

http://chirrup.org/cse382/index.php/lecture/index/09/

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

To run it in a running Fedora system, you need a virtual machine manager such as VMware or VirtualBox so you can install/run Windows in a virtual machine. That way, your Fedora applications continue to run while you simultaneously run Windows applications. I do that all the time.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I think you can use a multi-entry crontab like this:

0 0,5,10,15,20 * * * cmd-to-run
12 1,6,11,16,21 * * * cmd-to-run
24 2,7,12,17,22 * * * cmd-to-run
36 3,8,13,18,23 * * * cmd-to-run
48 4,9,14,19 * * * cmd-to-run

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Penguins...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Learn about C's bit-wise (boolean) logic. Example, for Xor, in C this can be expressed as:

int Xor(int a,int b)
{
    return a^b;
}

And Not(int a) like this:

int Not(int a)
{
    return !a;
}

I leave the rest to you for exercise... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I only see one problem. That is where you print the random number. IE, you do this:

    i = random.randint(1,10)
    print random.randint(1,10)

but you need to do this, because the second line with the print statement will get a new random number:

    i = random.randint(1,10)
    print i

So in your case, the print statement will not reflect the actual number assigned to i. :-)

efwon commented: Thanks that makes sense. I know I wouldn't have caught that. +0
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

First, unless you are going to limit yourself to Windows systems, don't use backslashes () for directory separators. Use a forward slash (/) instead. Windows will handle that just fine, but the backslash has special meaning in C/C++ programs and it won't work if you want to compile your code in Linux/Unix/OSX, et al.

As for QTreeWidget or QTreeView, it depends upon what you need to do. I assume you are using QT for your UI needs. You really need to first create an abstract tree structure that is not directly aligned with any particular GUI tool set. Then, once you have the tree built that represents the structure as it is, you can use QT, GTK, Wx, or whatever to render it on the display.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

When booting, hold down one of the function keys (like F2, F12, etc) until you hear a bunch of beeps. That should force the system into the bios setup. Some systems have a special key to do this (Lenovo Thinkpads, for example).

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You solve - we critique your solution. We DON'T do your homework for you... :-(

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

To all of your questions, the answer is "it depends"...

Part of the process of "finishing" a programming project is to specify hardware, software, and other requirements to run it. Re. database - does it require an industrial strength RDBMS such as Oracle, or will MySql suffice? Re. graphics - does it require HD video with high framerates, or will lower resolution and lower framerates work (if not as nicely)? How much RAM does it need? If >4GB then it also needs a 64-bit machine and operating system, even if you can use virtual memory (disc swap space), unless the hardware supports PAE to allow the OS to utilize more than 4GB of RAM (processes are still limited to 4GB).

All of these questions need to be considered before you determine if your software can run on a "normal" machine vs. a server or big workstation class system. These days, a "normal" computer can handle just about anything you throw at them, if not as effeciently as one that is sized to handle the specific load your are throwing at it. Example: my personal workstation is a dual 64-bit cpu with 8 3GHz cores, 8GB of RAM, 10+TB disc, dual HD display video. This is far faster and more capable than supercomputers of a few years ago, though I could use some more RAM... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The most common type of recursion is what we call "tail recursion" - a function directly calling itself, which is what you are doing here. There is indirect recursion where a function A calls function B, which somewhere down the line agains calls to function A.

So, yes your FUNCTION is recursive. A recursive program is something else entirely... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Depending upon the hash algorithm and the order of the table, collisions are common, so you have to traverse the chain to determine if you have a match if you are doing a lookup/comparison. With a sorted array, searches are nominally slower, but as deceptikon said, range searches and ordered output is a LOT simpler. I have written both types of collections in my past, and except for certain situations (random lookups, and low chance of collision), I have found that sorted arrays are preferable in the general case.

So, the rules are probably thus:

  • if you are doing random lookups and don't need range searches, use a hash table.
  • if you need to acces things in sorted order (range searches, etc), then a sorted array or some sort of B-Tree is preferable.
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Better idea? Donate them to a school or other charitable organization and take the tax deduction.

<M/> commented: brilliant idea! +5
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

C and D drive designators are Windows constructs. AFAIK, they have nothing to do with OSX.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The only means to assure that your old data is not recoverable on discarded gear is to remove the hard drives, mount them as an external drive on another computer, and wipe the disc with an appropriate shredder software. Alternatively, if the system still boots and has a bootable usb/cd/dvd port/drive, then you can boot something like Linux from removable media and shred the data using that. Example, booting a live CD with Linux, you would generally do this (at a minimum): dd if=/dev/zero of=/dev/sda
That will write 0 bits to all sectors of the disc. You can also use of=/dev/random which will write random data to all sectors. Actually, doing both is better. Not NSA-level disc erasure, but recovering any data after that is quite likely impossible unless you are the NSA with gazillion$ in specialized hardware, clean-rooms, and software that literally no-one else in the world possesses.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Also, providing the error output that you get is helpful as well. FWIW, the GNU Make documentation is quite good. Go here: http://www.gnu.org/software/make/manual/make.html

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Usually, you will need to also pass the size of the elements, as in:
void randomProgram(char random[][], size_t max1, size_t max2)
where max1 is the size of the first element, and max2 the size of the second. Then you can process it with something like this:

for (size_t i = 0; i < max1; i++)
{
    for (size_t j = 0; j < max2; j++)
    {
        doSomethingWith(random[i][j]);
    }
}

Of course, this is where in C++ we use vectors of vectors. You can much more easily deal with them in code.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Build a system with Intel workstation/server motherboard (dual CPU capable - a gazillion GB of ram space available) and an nVidia graphics card. They are reliable, fast, and well supported by Intel directly. I did that about 5 years ago, and if upgrading now, that's what I'd do again. At this point, I have an outdated system - 2x 3GHz quad core CPUs, 8GB RAM (only using 1/2 the slots available), and an nVidia 8800GT video card with dual 1920x1200 displays. In 5 years, I have had some RAM overheating problems, but re-arranging the SIMMs fixed that. For such a system, absolutely use fully-buffered ECC RAM. When my RAM was overheating, instead of failing entirely, the system was able to map the failing stick out of use automatically. All I saw (until I looked at the thermal monitor) was that I suddenly had 6GB instead of 8GB of RAM!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What JorgeM said is basically correct. Some simple math is required to decode IP addresses (I used to teach this in elementary networking classes to AT&T technicians, most with a high-school education) for a network admin position, but this is simple for anyone with high-school math. To be a network engineer (and all that the title "engineer" entails), then math at least through differential calculus is needed, plus a degree from a accredited educational institution. There are exceptions (I am one), but the basic skills cannot be shorted. I am a non-degreed engineer, but I have many university credits in graduate-level technical curricula, as well as the requisite maths and scientific knowledge.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

We do like to help people here at Daniweb, but we expect them to try to help themselves first! Especially for class exercises/problems. If we just give you the answer, it is simple cheating... Sorry, but most of us have worked to hard to learn this stuff just to give it away for nothing.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Look at the patterns. Each parameter in the config file has an '=' sign in it. The part before the '=' is the parameter, and the part after is the parameter value. So, do this.

  1. Read line into buffer.
  2. Check for comment character ('#')
  3. if no comment, look for '=' using strchr(buffer, '=')
  4. if return value from strchr is not null, you now know you have a parameter + value.

I leave the bit about extracting the parameter+value up to you. I only help with school problems - I don't solve them for you!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

If you can't connect the monitor to another computer or video card to test if it is the culprit, see if you can see the problem when you run the monitor's built-in diagnostics. If it persists, it is the monitor. If it doesn't, then it is the video card - possibly with degrading video RAM.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Isn't this kind of where we are going with quantum computing, where a bit can encode more than 2 (0 or 1) values? Anyway, most of the cost would be involved with providing compatibility. Yes a 3-state computer could interpret (if instructed to do so) dual-state data, but it wouldn't be easy (or fast) to go the otherway, so anything generated using 3-state logic with a trinary computer would not be accessible by common 2-state machines...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Some C header files are not C++ safe. If you get compiler and/or linker errors when you try to do so, then "guard" the #include <someCheader.h> directives with extern "C" {...}. Example:

#ifndef MYCPPHEADER_H
#define MYCPPHEADER_H
// My C++ header file
extern "C" {
#include <someCheader.h>
}
.
.
.
#endif // MYCPPHEADER_H
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You can extract the specific file from the compressed .bz2 tarball with this command:

tar -jxvf filename.tar.bz2 targetfilename

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This is a thread almost a year old. Please don't hijack it, even if your subject is similar. I spent a LOT of time helping newbie14 with his problems. Read the thread, and check with Google Search. So, post as a new thread after you have done some research and tried to sort out your problems, then someone will probably help you through the rougher parts. FWIW, I do this on a consulting basis, and my clients pay me $200USD per hour for my expertise, and in my regular job as a senior systems engineer I make a good fraction of that on a daily basis. Time and my expertise/experience is my only asset. I like to contribute to this and The Linux Forums (also under the Rubberman handle), but try to understand that everyone who contributes to answering questions here has limited time on their hands - use it wisely! :-)

happygeek commented: well said! +11