825 Posted Topics
Re: Why convert to binary tree? Is it even possible to convert from NxM grid to binary tree and keep the semantics of your 'grid'? | |
Re: C++ does not prevent you from accessing outside the bounds of an array. If you want exceptions on bounds checks look into standard containers that provide this type of thing. Here is an example using [icode]std::vector.at()[/icode][code]#include <vector> int main () { std::vector< int > v(10); for (int i = 0; … | |
Re: [EDIT] Sorry, forgot this was not the C forum. See below if you'd also like the C implementation. Bash script for lines and columns:[code]#!/bin/bash echo "cols: `tput cols`" echo "lines: `tput lines`"[/code] [/EDIT] The following will print out the number of rows/columns but I'm not sure of how to get … | |
Re: If you want to empty the tables of a database you are going to, at some point, use the facilities provided by the database designers to do so. This may be a command line script to drop tables or a program that uses the database API to do it programatically. … | |
Re: [code]$ pushd /Stallone/photos $ mv * ../ $ popd $ pushd /Aguilera/photos $ mv * ../ $ popd[/code] Of course, this moves [i]everything[/i] in the photos directory up one level - including other directories. You could limit that with globbing. For instance [icode]mv *.png ../[/icode] would only move files ending … | |
Re: It'd be helpful, as a start, if you gave an idea of what was going wrong. There is a lot of code there and even more context in your head that we are not privy to. | |
Re: The first example associates the const-ness with the value returned from the call. In the second example you are specifying that the call can not modify the object being invoked. | |
Re: [icode]delete p;[/icode] [i][b]invokes[/b][/i] the destructor for pointers. Putting a call to [icode]delete[/icode] in a destructor is only applicable if there is memory maintained within the object itself. | |
Re: When reading character-by-character you have to be aware of the newline in the buffer. Consider the following:[code]#include <iostream> int main () { char c = 0; while (std::cin.get(c)) { if (c == '\n') std::cout << "<NEWLINE>" << std::endl; else std::cout << c << std::endl; } return 0; }[/code] and the … | |
Re: [quote]Examples of copyright infringement may include borrowing significant portions of another's work in the creation of a new work...[/quote] From [url=http://www.lib.uconn.edu/copyright/plagiarismVsCopyright.html]here[/url]. I am certainly not a laywer. For a definitive answer you need to read the GPL license and probably contact a legal authority. | |
Re: [b]WaltP[/b] is suggesting that you mention errors but do not provide them. This requires us to now copy, paste and compile your code - likely on a different platform and with a different compiler than your own. If you copied the errors you were getting it would be helpful. Also, … | |
Re: Yes, you can. You can not have conflicting values, however. For instance, the following will not work:[code]enum enum1 { FOO , BAR } e1; enum enum2 { BAR, BAZ } e2;[/code] due to the redefinition of the enum tag [icode]BAR[/icode] | |
Re: Using [icode]sed[/icode] you can look for spaces and tabs [icode][ \t][/icode] (extended regular expressions will allow modifiers to that). Then you can replace with a comma. The general format of the sed search/pattern/replace is: [icode]s/PATTERN/REPLACEMENT/g[/icode] I added the [icode]g[/icode] on the end as it is a modifier to include all … | |
Re: You could specialize for the same type. Something similar to :[code]template< class T1, class T2 > class Different { public: Different(const std::pair< T1, T2 >& somePair) { l2r.insert(somePair); r2l.insert(std::make_pair(somePair.second, somePair.first)); } virtual T1 find(const T2& key) { return r2l[key]; } virtual T2 find(const T1& key) { return l2r[key]; } private: … | |
Re: The following line looks problematic:[code]fileVector entry(string firstname,string lastname,string idnumber,string class1, string class2,string class3,string hours,string classification,string degreetype, string thesis );[/code] Your compiler should have complained about that in that you are not allowed to have types next to the arguments in a constructor or function call. You error is probably related … | |
Re: For an introduction, look at [url=http://en.wikipedia.org/wiki/Huffman_coding]Huffman Encoding[/url]. There is certainly [i]much[/i] more than just that - but it should give you a start to get an understanding. | |
Re: Is there any reason you cant use a [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms682022(v=vs.85).aspx]programmatic[/url] approach. Or, at the minimum just output a large amount of blank lines? | |
Re: I'd suggest you move to C++ containers ([icode]std::string, std::remove_copy_if[/icode]) to make your life easier but that is another issue. The easiest way to remove elements from an array is to create a new array of exactly the same size as the original. Loop over each value in the original array … | |
Re: Show us what code you [i]did[/i] use and perhaps we can help you understand why it did not work. | |
Re: Well, the effect is due to how your are writing ([icode]>>[/icode]) to the file not necessarily due to the HERE document. I can think of a couple of solutions that may work depending on your setup. If you have a set front matter and tail matter you can place them … | |
Re: Containers are permitted as template arguments. Consider:[code]template < typename T, class E > bool contains (const T& haystack, const E& needle) { typename T::const_iterator F = haystack.begin(), L = haystack.end(); for (; F != L; ++F) if (*F == needle) return true; return false; }[/code] You can use that like:[code] … | |
Re: What would be the point of overloading two operators at the same time? Suppose you did what you were suggesting in your post - you would get functionality similar to [icode]data[x] = y[/icode]. What happens if you want to read that variable now? There is no support for just [icode]data[x][/icode] … | |
Re: There are libraries that try to provide this behavior across multiple platforms. [url=http://pdcurses.sourceforge.net/]PDcurses[/url] is one example. | |
Re: I don't have the context of your previous conversation, but why would something like a vector not work for you?[code] M& Insert(std::vector< MyTypes >& args) { for (int I = 0; I < args.size(); ++I) P.push_back(Args[I]); return *this; }[/code] | |
Re: It depends on who you want to manage the memory. If you have an agreement with the caller that the returned pointer is now 'owned' in the calling context then return dynamic memory as suggested by [b]gerard4143[/b]. This requires that the contract be upheld or a memory leak will occur. … | |
Re: Supposing you have sudo abilities, just open the terminal you are most used to and enter [icode]sudo bash[/icode]. Root shell session. Feel free to substitute [icode]bash[/icode] with your favorite shell, of course. | |
Re: You can not return a string. You must return a numeric value. So changing [icode]"$fileName__0"[/icode] to something like [icode]0[/icode] would work. | |
Re: Any reason you are not just using [icode]grep $uniqueValue Full_*[/icode]? | |
Re: You will have to check the value of [icode]errno[/icode] to find the exact problem. From the man pages of [icode]write[/icode]:[code]ERRORS EBADF fd is not a valid file descriptor or is not open for writing. EINVAL fd is attached to an object which is unsuitable for writing. EFAULT buf is outside … | |
Re: Are you sure your implementation of [icode]new[/icode] doesn't already provide virtual memory backed by disk space? Have you run into the issue of [icode]new[/icode] returning NULL (as opposed to throwing [icode]bad_alloc[/icode])? | |
Re: It removes html/xml style tags from the input file. [code] s/ # Search for ... < # Something that begins with '<' [^>] # and continue while there isn't a '>' * # for zero-or more characters > # Ending with a '>' character // # replace previous match with … | |
Re: How, with the first method, would you expect to support something like [icode]a = b = c;[/icode]? | |
Re: The way [b]Banfa[/b] suggests is a common way to do this. Macros are another way you will see. Something like[code]#define MAKE_COMMON_FOO(f,fun) struct foo f; \ f.func = fun[/code] Which would be used like[code]MAKE_COMMON_FOO(bar,func); bar.func(4);[/code] The advantage of the macro is that as the struct evolves the changes to the code … | |
Re: Your examples are mixing character variables with integer variables and looping over different ranges. I'm not sure why you expect common behavior if you do not provide common code... | |
Re: Probably because you are giving input [icode]1 4[/icode] instead of [icode]1 3[/icode]. | |
Re: Neither case will work for me. The tags for case statements must be constants, they can not be the result of a function call. It might be the case that, on your platform, the [icode]isdigit[/icode] is evaluated at pre-processor time to be 1 allowing for you to compile. Can you … | |
Re: A good programmer is a problem solver first. If you can not solve problems programming chops are a moot point. Also, this is the C forum, your topic (and question) are off-topic for this area. Consider, instead, the [url=http://www.daniweb.com/community-center/3]Community Center[/url]. | |
Re: Superscripts and subscripts are an artifact of a rendering process; they are not native to the C++ language. | |
Re: You must be careful with what you are asking. A pointer to a [icode]std::string[/icode], a pointer to a character array and a [icode]std::string[/icode] are all distinct and the process by which you concatenate will be different for each. What types are you dealing with? | |
![]() | Re: You may look at how other cross-platform software does this. Consider boost - which is fairly compatible on multiple platforms. In boost you will find a [icode]select_platform_config.hpp[/icode] which has code similar to[code]#if defined(linux) || defined(__linux) || defined(__linux__) // linux: # define BOOST_PLATFORM_CONFIG "boost/config/platform/linux.hpp" #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) // … |
Re: You want to connect as a new user or you want to connect as the same user with different credentials? | |
Re: You want a [i]function generator[/i] or a function that will generate a 128bit random [i]number[/i]? You may be out of luck for a function generator. As for the random number, [url=http://stackoverflow.com/a/1546037/128138]this[/url] has a lot of relevant information. | |
Re: The [icode]test: extra argument `how'[/icode] should tip you off that it's not your program running. Try renaming your program to something like [icode]foo[/icode] and try again. Your shell already has a binary named [icode]test[/icode] that will be used by default. By not providing an explicit path, you have invoked the … | |
Re: You create enough room for a single int with [icode]int * data2 = new int();[/icode] You are accessing that memory as if it were an array. You probably mean [icode]int * data2 = new int[MAX_SIZE];[/icode] where [icode]MAX_SIZE[/icode] is the size of the array you want to support. Either that, or … | |
Re: When I run your example I get [code]/user/test /user/test/program[/code]I fail to see how that differs from what you want. | |
Re: There isn't any reason to delete the two you are not using. They aren't hurting anything. If you only want a single installation on your machine then you need to re-install the OS and force it to remove existing partitions and use the entire disk. | |
Re: [icode]graph *g;[/icode] creates a pointer (to memory) but you fail to provide any memory to point to. You can do one of three things: [LIST] [*] Create an object instead of a pointer ([icode]graph g;[/icode]) [*] Create an object and assign the pointer to that objects address ([icode]graph g, *gp … | |
Re: Consider why you must convert to C. I cont see many reasons where C would be necessary over C++. | |
Re: If you quote that then you should have no problem. For instance:[code]#define BLOCK(msg) blockHandler(msg) void blockHandler(const std::string& blk) { std::stringstream ss(blk); std::string s; while (ss >> s) std::cout << "Token: " << s << std::endl; } int main () { BLOCK("This is a quoted block in the program"); return 0; … | |
Re: They are bash variables. Look for 'special parameters' [url=http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html]here[/url]. |
The End.