2,384 Posted Topics

Member Avatar for Kandeep

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.

Member Avatar for Dave Sinkula
-1
84
Member Avatar for neithan

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 …

Member Avatar for Dave Sinkula
0
611
Member Avatar for VernonDozier
Member Avatar for pspwxp fan

[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 …

Member Avatar for pspwxp fan
0
231
Member Avatar for lipun4u

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.

Member Avatar for mrnutty
0
136
Member Avatar for nav33n

[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, …

Member Avatar for nav33n
6
313
Member Avatar for swolll

[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]

Member Avatar for Zjarek
0
178
Member Avatar for neithan

[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 …

Member Avatar for marco93
0
674
Member Avatar for Samyx

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 …

Member Avatar for Samyx
1
151
Member Avatar for cwats124
Member Avatar for pspwxp fan
-1
132
Member Avatar for DCV

[CODE]void [COLOR="Red"]roster::[/COLOR]addPlayer(string first, string last, int number, string position) { cout<<"The function was called!\n"; }[/CODE]

Member Avatar for dkalita
0
150
Member Avatar for shahab.burki

[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].

Member Avatar for Dave Sinkula
0
115
Member Avatar for Grn Xtrm

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 …

Member Avatar for Dave Sinkula
0
4K
Member Avatar for Dixtosa
Member Avatar for axed

[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.

Member Avatar for axed
0
250
Member Avatar for C++NOOOB

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].

Member Avatar for Dave Sinkula
0
157
Member Avatar for ochambo
Member Avatar for Dave Sinkula
0
144
Member Avatar for vileoxidation

[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]

Member Avatar for vileoxidation
0
249
Member Avatar for 0805638

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] …

Member Avatar for Grn Xtrm
-1
83
Member Avatar for new programer

[code]else if ( delta [COLOR="Red"]=[/COLOR]= 0 ) // compare, don't assign![/code]

Member Avatar for new programer
0
79
Member Avatar for suricata

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.

Member Avatar for suricata
0
260
Member Avatar for saintandsinner

[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.

Member Avatar for Dave Sinkula
0
80
Member Avatar for Towely

[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.

Member Avatar for Towely
0
231
Member Avatar for grudgemuch

[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]

Member Avatar for Dave Sinkula
0
285
Member Avatar for nanoooosha

[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 …

Member Avatar for Dave Sinkula
0
136
Member Avatar for brando|away

[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 …

Member Avatar for Dave Sinkula
0
142
Member Avatar for bobrien314

It seems like a very quick test to see if such behavior is currently already available.

Member Avatar for William Hemsworth
0
80
Member Avatar for sweetsympathy17

umm, [URL="http://www.daniweb.com/forums/announcement118-2.html"]ok[/URL]

Member Avatar for William Hemsworth
-1
74
Member Avatar for Daithi
Member Avatar for SARPONG

Short answer: no. [URL="http://www.daniweb.com/forums/announcement8-2.html"]Longer answer[/URL].

Member Avatar for Dave Sinkula
0
34
Member Avatar for tux4life

It might be nice to provide some "test" or "driver" code in which some example of this function's input and output are demonstrated.

Member Avatar for Dave Sinkula
1
907
Member Avatar for ulcimd1

[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 …

Member Avatar for Tom Gunn
0
116
Member Avatar for vladdy191
Member Avatar for plobby

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]

Member Avatar for mrnutty
0
140
Member Avatar for duggydiggy

The result of a cast is not an lvalue. I believe that is the case for the result of many operators.

Member Avatar for MrNoob
0
72
Member Avatar for Se7Olutionyg

Don't put function definitions in a header file. You can only have one main() function.

Member Avatar for Se7Olutionyg
0
66
Member Avatar for Dretkal
Member Avatar for Narue

[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?

Member Avatar for Dani
0
202
Member Avatar for duggydiggy

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 = …

Member Avatar for duggydiggy
0
189
Member Avatar for Caglow
Member Avatar for Ancient Dragon
Member Avatar for Dave Sinkula
0
351
Member Avatar for anbuninja

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 …

Member Avatar for Dave Sinkula
0
102
Member Avatar for dumrat

[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?

Member Avatar for jyh5
0
133
Member Avatar for arcticM

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? …

Member Avatar for Dave Sinkula
0
113
Member Avatar for adi.shoukat
Member Avatar for aomran

My guess is that it means just what it says. Do you suppose you could post relevant code or some sort of context?

Member Avatar for aomran
0
2K
Member Avatar for nateuni

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.

Member Avatar for gerard4143
0
131
Member Avatar for vileoxidation

[url]http://tinyurl.com/n5lq4w[/url] Neither [ICODE]%c[/ICODE] nor [ICODE]%d[/ICODE] are for double.

Member Avatar for Golam Kausher
0
192
Member Avatar for oling

[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 …

Member Avatar for oling
0
2K
Member Avatar for buriza

[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]

Member Avatar for NathanOliver
0
100

The End.