2,384 Posted Topics

Member Avatar for Young Teck 06

>I need some C++ recommendation books for beginners. [url="http://www.daniweb.com/techtalkforums/thread10232.html"]C++ Books[/url] >I have $50 so no expensive books. [url="http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=YG5c2YDAg7&isbn=020170353X&TXT=Y&itm=1"] Accelerated C++: Practical Programming by Example[/url] $39.99

Member Avatar for Dave Sinkula
0
121
Member Avatar for bemrag

> ı wrote the program like that but it doesn't work. It doesn't look like you've fixed [url="http://www.daniweb.com/techtalkforums/post60043.html#post60043"]this stuff[/url] yet.

Member Avatar for Dave Sinkula
0
111
Member Avatar for zoey

[QUOTE=zoey]can any one help me with the code to reverse 2 strings with [b]unequal[/b] number of characters in them.[/QUOTE]The emphasis on [i]unequal[/i] to me seems to imply that you already know how to reverse a single string, but are having difficulty expanding on this. Perhaps show us this code for …

Member Avatar for Narue
0
151
Member Avatar for tonja1196

Would you want something like this on the end of the first if tree?[CODE] else { ++num; continue; } [/CODE] Here you make an assignment where to likely meant to compare.[CODE]else if ( total=[color=Blue]=[/color]num )[/CODE]

Member Avatar for Dave Sinkula
0
98
Member Avatar for Fleetfoot18

[CODE]#include <stdio.h> int main(int argc, char *argv[]) { int i; printf("argc = %d\n", argc); for (i = 0; i < argc; ++i) { printf("argv[%d] = \"%s\"\n", i, argv[i]); } return 0; } /* my output C:\Test>testpp.exe data.txt argc = 2 argv[0] = "C:\Test\testpp.exe" argv[1] = "data.txt" */[/CODE]

Member Avatar for Dave Sinkula
0
79
Member Avatar for jaeSun

If you can use stringstreams, then you can just use getline for each line and then use a stringstream of the line to pick off the ints. [CODE]#include <iostream> #include <sstream> #include <string> int main() { std::string line; while ( std::getline(std::cin,line) ) { std::istringstream iss(line); int value; while ( iss …

Member Avatar for Stack Overflow
0
277
Member Avatar for nicoletonyf

[QUOTE=jaeSun]this looks very familiar to me .... [/QUOTE]Were you [url="http://www.cpp-home.com/forum/viewtopic.php?t=7334"]here[/url]?

Member Avatar for jaeSun
0
196
Member Avatar for hansamurai
Member Avatar for Narue
0
117
Member Avatar for the b

See what's missing in the function definition?[CODE]void calculate_total ([b][color=Blue]float [/color][/b]total); /*...*/ void calculate_total (total) { cout << total; }[/CODE]At some point you'll probably want to initialize your [i][font=Courier New]total[/font][/i].[CODE]float total = 0;[/CODE]A [font=Courier New]float[/font] constant would be [font=Courier New]3.50[/font][font=Courier New][color=Blue]F[/color][/font], whereas a [font=Courier New]double[/font] constant would be [font=Courier New]3.50[/font].

Member Avatar for ZuK
0
189
Member Avatar for Narayan

Maybe something like this?[code] dptr = iter->second; if(dptr != NULL) { delete dptr; iter->second = NULL; }[/code]

Member Avatar for Narue
0
148
Member Avatar for ellas747

I've been playing along at home; any criticisms for this? [CODE]#include <stdio.h> #include <math.h> #include <float.h> #include <limits.h> int factorial(unsigned long n, unsigned long *result) { unsigned long i; for ( *result = 1, i = 2; i <= n; i++ ) { if ( *result > ULONG_MAX / i …

Member Avatar for Narue
0
1K
Member Avatar for coolmel55

[CODE]#include <iostream> class type { int data; public: type(int initializer = 0) : data(initializer) {} void method() { std::cout << "data = " << data << std::endl; } }; int main() { type object(42); object.method(); return 0; } /* my output data = 42 */[/CODE]

Member Avatar for letmec
0
129
Member Avatar for matika

[QUOTE=matika]#define ENDFILE "CTRL-Z"[/QUOTE]You have them enter this text? Or are you meaning a single keystroke? (If you mean a keystroke, I'd guess you're not doing this right.) [QUOTE=matika]what i need, i want the user 2 enter CTRL-X to end the program #define ........ "CTRL-X" ( what could i write here) …

Member Avatar for matika
0
191
Member Avatar for coolmel55

[url]http://www.cpp-home.com/forum/viewtopic.php?p=36920#36920[/url]

Member Avatar for coolmel55
0
455
Member Avatar for JECMAIL

>Is there a way to convert a user entered (cin) char to an integer? Why convert it, why not just use the chars '0', '1', ... 'A', 'B', ... ?

Member Avatar for Narue
0
175
Member Avatar for HinJew

You tell the compiler that WINDSPEED is a [font=Courier New]double[/font].[CODE]void WINDCHILL_OUT(double [color=Blue]WINDSPEED[/color], double TEMPERATURE, double WINDCHILL_INDEX) { double FARENHEIT; double SPEED; [color=Blue]WINDSPEED[/color](SPEED); FtoC(FARENHEIT, TEMPERATURE); TEMPinC(TEMPERATURE); WINDCHILL(WINDSPEED, TEMPERATURE, WINDCHILL_INDEX); cout << "\nWith a temperature of " << TEMPERATURE << " and a windspeed of\n" << WINDSPEED << " the windchill index …

Member Avatar for coolmel55
0
117
Member Avatar for coolmel55

>How do I find for example ; in the file now? [code]#include <iostream> #include <string> int main() { std::string line; while ( getline(std::cin, line) ) { std::string::size_type pos = line.find(";"); if ( pos != std::string::npos ) { std::cout << line << std::endl; } } return 0; }[/code] Feeding this source …

Member Avatar for coolmel55
0
301
Member Avatar for HinJew

[Whoa. I'd suggest ending your preference of CAPITALIZING SYMBOLS.] Read the error messages. [code]void TEMPinC() { cout << "Please enter the temperature in farenheit followed by enter\n"; cin >> TEMPERATURE; }[/code]I'd guess the message is something like this. [quote]'TEMPERATURE' : undeclared identifier[/quote] I find that self-explanitory. There is no variable …

Member Avatar for Chester1
0
93
Member Avatar for ray96

[code]#include <math.h> double degrees_to_radians(double degrees) { double PI = 4.0 * atan(1.0); return degrees * PI / 180.0; }[/code]

Member Avatar for Dave Sinkula
0
137
Member Avatar for jasweb2002

Show your code. Your preferred method can probably be very easily adapted, but I can't read your mind and see the code you have. This is a short example of what you could do. [code]#include <iostream> int main() { std::string text; while(std::cin >> text) { std::cout << "text: " << …

Member Avatar for jasweb2002
0
105
Member Avatar for XianBin

[QUOTE=Stack Overflow]Now moving inside main, lets take a look at our routines: [code][color=blue]int[/color] *pfun; [color=blue]char[/color] *pchar;[/code] [b]»[/b] These are your local variables. One is a pointer to an integer, and the other, a char array [or pointer].[/QUOTE]An array is not a pointer. The fewer times folks are told this, the …

Member Avatar for XianBin
0
146
Member Avatar for willow

[QUOTE=chound]As long it works why do u want to change it?[/QUOTE]Because it is not guaranteed to work in the future.

Member Avatar for Dave Sinkula
0
1K
Member Avatar for ohnbabygal
Member Avatar for tj

[code] if (b <= [color=Blue]max[/color]) [color=Red] min[/color] = b;[/code]Perhaps you should compare the current [font=Courier New]min[/font].[code] int max=0; //highest vaule int min=0; //lowest value[/code]You would probably want to initialize both to the first element in the list or else set the [font=Courier New]max[/font] to the lowest [font=Courier New]int[/font] value ([font=Courier …

Member Avatar for chound
1
260
Member Avatar for Anu

Skip 26. Or better yet, skip printing everything non-printable. [code] #include <stdio.h> #include <ctype.h> int main(void) { int i; for ( i = 0; i < 256; ++i ) { putchar(isprint(i) ? i : '.'); putchar(i % 16 == 15 ? '\n' : ' '); } return 0; } /* …

Member Avatar for chound
1
129
Member Avatar for raar

[code] #include <stdio.h> #include <limits.h> [color=Blue]struct type /* note: bit order is implementation-dependent */ { unsigned int a : 2; unsigned int b : 2; unsigned int c : 4; };[/color] void showbits(unsigned char byte) { unsigned char bit; for ( bit = 1 << (CHAR_BIT - 1); bit; bit …

Member Avatar for raar
0
178
Member Avatar for lindsay867
Member Avatar for felgall
0
128
Member Avatar for hiunnati

[code]if ( ! feof( fp ) )[/code] [url="http://www.cpp-home.com/forum/viewtopic.php?p=24389#24389"]http://www.cpp-home.com/forum/viewtopic.php?p=24389#24389[/url] [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351"]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351[/url]

Member Avatar for Dave Sinkula
0
174
Member Avatar for vivekgalatage

> Is there any tool which will detect the unused methods of a class in a C++ project? [url="http://www.gimpel.com/"]PC-lint[/url]?

Member Avatar for Chainsaw
1
150
Member Avatar for meirre

One way:[code]#include <stdio.h> int main() { int number[3][3] = { {1,2,3}, {2,3,4}, {3,4,5} }; struct { int value, times; } result [ sizeof number / sizeof **number ] = {0}; size_t i, j, k; for ( i = 0; i < sizeof number / sizeof *number; ++i ) { for …

Member Avatar for Dave Sinkula
1
93
Member Avatar for kohkohkoh

[code]name[i] = tolower(name[i]);[/code]The function [font=Courier New]tolower[/font] operates on a single character, not a [font=Courier New]std::string[/font]. [code] for ( int pass=0; pass <3; pass++ ) for ( int i=0; i <3; i++ ) if ( name[i] > name[i+1] ) { temp = name[i]; name[i] = name[i+1]; name[i+1] = temp; }[/code]If i …

Member Avatar for kohkohkoh
0
128
Member Avatar for Kiwiman

Correct headers will be called..... If you only need one, why not just show it? I can't use any other functions than those above. It is unfortunate that you would be required to use [gets](http://www.eskimo.com/~scs/C-faq/q12.23.html). Code is much easier to read when it is within [code][/code] int main(){ char filename[30]; …

Member Avatar for Dave Sinkula
0
281
Member Avatar for Killer_Typo
Member Avatar for Stack Overflow
0
355
Member Avatar for Sukhbir

>`char *ptr="abc";` >`char *ptr1;` >`while(*ptr1++=*ptr++); //IT IS WORKING` >`while((*ptr1)++=(*ptr)++); //ERROR[/code]PLS EXPLAIN ME.` You haven't initialized ptr1 : when you first dereference it, it is already undefined behavior, so "IT IS WORKING" is just plain "luck(?)". In the "ERROR" line, the result of the `++` operator is not an lvalue, so …

Member Avatar for Chainsaw
0
141
Member Avatar for beezybeem

[b][url="http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2"][b][b]We only give homework help to those who show effort[/b][/b][/url][/b] [code]//#include <iostream> // and other headers // function prototypes int main(void) { // your code here return 0; } // definitions for functions used in main[/code]

Member Avatar for Stack Overflow
1
150
Member Avatar for vudatalark

[QUOTE=vudatalark]how many ways can you pass parameters to a function in c++[/QUOTE]Do you mean this? [list=1] [*]By value. [*]By pointer. [*]By reference. [/list]

Member Avatar for Chainsaw
1
296
Member Avatar for scott_6169
Member Avatar for littletimmy

[url]http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.5[/url] [url]http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.7[/url]

Member Avatar for Dave Sinkula
1
200
Member Avatar for JustinsCJ5

[QUOTE=JustinsCJ5]However i am not quite sure on how to begin writing this. Can anyone give me help on using loops with arrays?[/QUOTE][code]#include <iostream> int main(void) { int size; std::cout << "size? "; std::cin >> size; int *array = new int[size]; for(int i = 0; i < size; ++i) { std::cout …

Member Avatar for Dave Sinkula
0
130
Member Avatar for Transworld

Playing along at home, this is what I had.[code]#include <stdio.h> int main(void) { int a, b, c, i = 0, limit = 500; puts("Pythagorean Triples:"); for ( a = 1; a < limit; ++a ) { for ( b = a + 1; b < limit; ++b ) { for …

Member Avatar for Transworld
1
7K
Member Avatar for cwobie

You may want to use a [font=Courier New]struct tm[/font] to hold integer values for the month, day, and year that the user enters. But keep in mind that this structure normally has the month from 0-11 and the year is a two-digit value based on the year 1900 (that is, …

Member Avatar for Dave Sinkula
1
91
Member Avatar for lin-da

[QUOTE=lin-da]and in main fuction I want to do [color=Red] U_pp = U_past; //save U_past data in U_pp U_past = U_future; //save U_future data in U_past U_future = new_data; //get new data for U_future[/color] [/QUOTE]Arrays cannot be copied or assigned: you must copy each array element explicitly (or use an equivalent …

Member Avatar for Dave Sinkula
1
99
Member Avatar for kohkohkoh

Have you done swapping of integers? The same principle applies. Make a temporary copy of [i][font=Courier New]a[/font][/i], write [i][font=Courier New]b[/font][/i] to [i][font=Courier New]a[/font][/i], write the temporary copy to [i][font=Courier New]b[/font][/i]. With integers, you could use simple assignment; with C-style strings, you use strcpy.

Member Avatar for Dave Sinkula
1
114
Member Avatar for shortd81

[QUOTE=shortd81]Need some help. Don't know anything about programming except HTML, would like to know where I should start to learn the language. :?:[/QUOTE]Which language -- C or C++? A [url="http://www.daniweb.com/techtalkforums/thread10232.html"]book[/url] maybe?

Member Avatar for shortd81
1
177
Member Avatar for littletimmy

[url="http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15"]http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15[/url]

Member Avatar for littletimmy
0
148
Member Avatar for lara_
Member Avatar for Dave Sinkula
0
323
Member Avatar for iamhe

[QUOTE=iamhe]This is giving me a headache...can someone please tell me why these statements ARE NOT equivalent? ------------------------- The first statement works; the second does NOT. The second always evaluates to false. Why? Both of these vars are bools.[/QUOTE]Maybe the problem is elsewhere.[code]#include <iostream> int main() { bool a, b; //Statement …

Member Avatar for iamhe
2
167
Member Avatar for cford

[QUOTE=cford]How do I make a greeting a named constant rather than a literal constant?[/QUOTE]I'm not sure if I completely understand what you are asking. [code]#include <stdio.h> int main( void ) { const char named_constant[] = "string literal initializer"; puts("literal constant"); /* (1) */ puts(named_constant); /* (2) */ return 0; } …

Member Avatar for alc6379
1
115
Member Avatar for Transworld

[QUOTE=Transworld]Would I have to go about doing the math manually and make my own function? Is there some built in function I can use to be lazy? Is there some totally easier way that I am oblivious to?[/QUOTE]I will assume you mean you would like to display the value of …

Member Avatar for Transworld
0
674
Member Avatar for damionspencer

[QUOTE=Chainsaw]I imagine it complains about these lines: using std::cout; using std::cin;[/QUOTE]Why? [QUOTE=Chainsaw] try just "using std;" instead.[/QUOTE]ITYM[code]using namespace std;[/code]Except in 'toy' programs, you really don't want to grab the whole namespace -- doesn't that kind of defeat the purpose of the namespace?

Member Avatar for Dave Sinkula
2
180

The End.