2,384 Posted Topics
Re: A conversion function such as [URL="http://www.daniweb.com/code/snippet216829.html"]strtod[/URL] can do the hard work of checking for valid characters in allowable locations in the input string ([URL="http://www.dinkumware.com/manuals/?manual=compleat&page=stdlib.html#strtod"]which is not entirely trivial[/URL]). If the format is correct, the converted value is returned. You can then add range checking to the converted value. | |
Re: Ballpark? [code]#include <iostream> #include <string> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main() { string init[] = {"one", "two", "three", "four", "five" }; vector<string> vec[COLOR="Red"](init, init + sizeof init / sizeof *init)[/COLOR]; copy(vec.begin(), vec.end(), ostream_iterator<string>(cout, "\n")); return 0; } /* my output one two three four five … | |
| |
Re: [QUOTE=pspwxp fan;1011958]Installed it and stuff with ease, and decided to test it with a helloworld program. Thing is, when i decided to compile the program, it wouldn't compile. [CODE]* Release" uses an invalid compiler. Skipping... Nothing to be done.[/CODE] Followed some google links that told me to see the compiler … | |
Re: Since string is in the std namespace don't grap everything: [CODE]using namespace std;[/CODE] Be specific: [CODE]using std::cout; using std::cin; using std::endl;[/CODE] Or choose a new class name different from [ICODE]string[/ICODE]. Then you'll be left "more normal" errors to fix. | |
Re: [QUOTE=nav33n;1005968]Hi all, I have a suggestion (not sure if it has already been discussed). In the profile, at the community tab, we have, for example, If this number [i]10[/i] is made a href linking to all the code snippets posted by that particular user, it would be great. At present, … | |
Re: [URL="http://www.daniweb.com/forums/post155265.html#post155265"]Avoid Loop Control Using eof()[/URL] What to do instead? Check for successful data input. [CODE]while (data >> number)[/CODE] [edit]Also, this is undefined behavior (a bad thing to do): [CODE]count = count++;[/CODE] [url]http://c-faq.com/expr/seqpoints.html[/url] Keep it simple (and correct): [CODE]count++;[/CODE] | |
Re: [QUOTE=neithan;1009152]Yes but, why don't use system("pause") at all? I mean what's wrong with it?[/QUOTE] [url]http://cboard.cprogramming.com/c-programming/56441-can-someone-help-me-understand-example-program.html#post394525[/url][QUOTE] >system("pause"); This is all kinds of wrong. First, while system is a standard function and thus portable, the argument you pass to it cannot be portable because it relies on the system command interpreter. If … | |
Re: If your return value for the error condition is not checked, why would the loop break? [CODE]void permute (int *A, int n) { int i = 0; for (i=0; i<n; i++) { /* Pick a random element to move to i-th position. */ [COLOR="Red"]int k = discrete_uniform (i+1, n-1);[/COLOR] int … | |
Re: [CODE]void [COLOR="Red"]roster::[/COLOR]addPlayer(string first, string last, int number, string position) { cout<<"The function was called!\n"; }[/CODE] | |
Re: [QUOTE=Arcaiz;1010962]1. Do these code valid? [CODE]port=atoi(argv[2]);[/CODE] I suppose atoi() isn't ANSI C[/QUOTE]You suppose wrong. [url]http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.10.1.2[/url] [QUOTE=Arcaiz;1010962]You could use this for exchange [CODE]sprintf(argv[2], "%d", port)[/CODE][/QUOTE]I generally avoid writing to argv. [URL="http://groups.google.com/group/comp.lang.c/browse_thread/thread/4a8b49ecb38c3ccf/69905b99d1a7cba6?ie=UTF-8&q=writable+argv+group:comp.lang.c#69905b99d1a7cba6"]Related material[/URL]. | |
Re: This is just some of my tinkering on the topic: [code]#include <stdio.h> void diamond(int size) { int i, j, i2; for ( i = 0, i2 = size / 2; i < size; ++i ) { int stars = i <= i2 ? 2 * i + 1 : 2 … | |
Re: [url]http://david.tribble.com/text/cdiffs.htm[/url] | |
Re: [CODE]class PriceFeed { public: PriceFeed(vector<string>& tickers) { // init(tickers); } }[COLOR="Red"]; // missing semicolon[/COLOR] [/CODE][CODE] PriceFeed [COLOR="Red"]*[/COLOR]pf = new PriceFeed(tickers); // Error on this line[/CODE]You'll want a pointer. | |
Re: I seem to recall something about using a [URL="http://groups.google.com/group/comp.lang.c++/browse_thread/thread/223cce100987cc39/bf8d13ef635a8d69?ie=UTF-8&q=vector%3Cbool%3E+proxy+group%3Acomp.lang.c%2B%2B&pli=1"]proxy[/URL], but I don't remember enough of it to do much more than mention it and some quick & dirty [URL="http://groups.google.com/groups?sourceid=groowe&ie=UTF-8&q=vector%3Cbool%3E%20proxy%20group%3Acomp.lang.c%2B%2B"]search[/URL]. | |
Re: When you set your project up, you want it to be a console application. | |
Re: [code]StaffMember([COLOR="Red"]string &[/COLOR]string1, [COLOR="Red"]string &[/COLOR]string2, [COLOR="Red"]string &[/COLOR]string3)[/code] [code]const char *ptr = lineToParse[COLOR="Red"].c_str()[/COLOR];[/code] | |
Re: It appears that you don't know how to use a goto in C++, so that puts you about even up with functions from what you say: prefer learning functions first. Or just inline the code (copy and paste between the curly braces). [code]if( a = "true")[/code] In the above [ICODE]=[/ICODE] … | |
Re: [code]else if ( delta [COLOR="Red"]=[/COLOR]= 0 ) // compare, don't assign![/code] | |
Re: That could be close to making sense to me, but not quite. Are you trying to do something more like this? [code]est[var].a=0;[/code] Or perhaps you could elaborate more about what you're trying to do. | |
Re: [CODE]Circle( double r = 0.0, int x = 0, int y = 0 );[/CODE] Prototypes aren't enough, you'll have to define the functions too. | |
Re: [QUOTE=Towely;1007651]I've added in the brackets; I did it in Programmer's Notepad so I made sure I did all of them absolutely right.[/QUOTE]Nope. You didn't get all of them. And you're missing semicolons on a number of statements as well. | |
Re: [ICODE]%d[/ICODE] -> [ICODE]%02d[/ICODE] [code]#include <stdio.h> int main(void) { int h = 1, m = 1, s = 1; printf("%02d:%02d:%02d", h, m, s); return 0; } /* my output 01:01:01 */[/code] | |
Re: [QUOTE=nanoooosha;1006420]I have this function void smallAverage(int *array, float *average, int *numSmallerThanAverage );[/quote]Is that signature a design requirement? Knowing the size of the array is generally done by also passing a size parameter, or else there must be some sort of value used as a sentinel to stop looping. I'd prefer … | |
Re: [QUOTE=Grn Xtrm;1005551]When I use classes in other files I use: [code=cplusplus] #include "filename.cpp" [/code] I put this line in the file containing my main() function. This lets you use the class in your main() function.[/QUOTE]Sooner or later you'll need to learn that this is the wrong thing to do. Generally … | |
Re: It seems like a very quick test to see if such behavior is currently already available. | |
Re: umm, [URL="http://www.daniweb.com/forums/announcement118-2.html"]ok[/URL] | |
Re: Folks might find it helpful if you'd post "Plot.h". | |
Re: Short answer: no. [URL="http://www.daniweb.com/forums/announcement8-2.html"]Longer answer[/URL]. | |
Re: It might be nice to provide some "test" or "driver" code in which some example of this function's input and output are demonstrated. | |
Re: [QUOTE=ulcimd1;1000821]I am learning about code auditing, and I have a question relating to the argc/argv[] variables. I think that the argc is an integer type, so would enough command line arguments overflow the buffer? I know that it's a stretch, but I am looking for the third vulnerability in our … | |
Re: [url]http://c-faq.com/malloc/crash.html[/url] | |
Re: Read user input as a string. Attempt to convert to a number. If all of the string is used to convert a number, you're done. [url]http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2[/url] | |
Re: The result of a cast is not an lvalue. I believe that is the case for the result of many operators. | |
Re: Don't put function definitions in a header file. You can only have one main() function. | |
| |
Re: [threadjack]Somewhere around here I'd asked about retaining the username for an Advanced Search following an unsuccessful search attempt (just like it retains the keyword(s). Is this something that can be added? | |
Re: So the question you are asking is in regard to the output of the code on top when using gcc? [code]#include <stdio.h> int strlenA(const char *str) { const char *eostr = str; while ( *eostr++ ); return eostr - str; } int strlenB(const char *str) { const char *eostr = … | |
Re: [url]http://c-faq.com/fp/fpequal.html[/url] | |
| |
Re: A compile attempt (gcc): [QUOTE]main.cpp: In function `int main()': main.cpp:19: error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::string' main.cpp:6: error: in passing argument 2 of `void getHours(int&, std::string&)' main.cpp:20: error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type … | |
Re: [QUOTE=Ancient Dragon;979095]Years ago I didn't do either because all it did was increment a global varialble.[/QUOTE]Just out of curiousity, what was the type of the variable, and on what platform? And related, ain't an integer increment on a PC on atomic operation? | |
![]() | Re: I'm not a fan of typedefed pointers, I find them obfuscatory.[QUOTE=arcticM;996264]I did realloc to add a new writter to my dynamic array of writers like that- [CODE]WriterPtr ptr=(WriterPtr)realloc(*pWriter,(*psize+1)*sizeof(WRITER)))==NULL); //I did a check that there was enough space *pWriter=ptr; (*psize)++; [/CODE][/QUOTE]Are you trying to do too much in that first line? … |
Re: Open files in binary mode. | |
Re: My guess is that it means just what it says. Do you suppose you could post relevant code or some sort of context? | |
Re: Do you generally catch the return value of [ICODE]printf[/ICODE]? If you don't need to use the return value, you can quietly discard it if you so choose. | |
Re: [url]http://tinyurl.com/n5lq4w[/url] Neither [ICODE]%c[/ICODE] nor [ICODE]%d[/ICODE] are for double. | |
Re: [QUOTE=oling;992529]However, the strange thing, it doesn't matter whether I have the [B]int[/B] variable signed or unsigned - the program always returns the same number: int y=0xFFFF returns 65,535 unsigned y=0xFFFF returns 65,535 (should return -1) Any advice?[/QUOTE]I'm rather curious why you think an unsigned value should be negative, but do … | |
Re: [ICODE][COLOR="Red"]'[/COLOR]+[COLOR="Red"]'[/COLOR][/ICODE], [ICODE][COLOR="Red"]'[/COLOR]-[COLOR="Red"]'[/COLOR][/ICODE], [ICODE][COLOR="Red"]'[/COLOR]*[COLOR="Red"]'[/COLOR][/ICODE], [ICODE][COLOR="Red"]'[/COLOR]/[COLOR="Red"]'[/COLOR][/ICODE] [edit]Assignment/comparison:[code]if(err =[COLOR="Red"]=[/COLOR] 1)[/code] |
The End.