2,384 Posted Topics
Re: >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 | |
Re: > ı 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. | |
Re: [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 … | |
Re: 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] | |
Re: [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] | |
Re: 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 … | |
Re: [QUOTE=jaeSun]this looks very familiar to me .... [/QUOTE]Were you [url="http://www.cpp-home.com/forum/viewtopic.php?t=7334"]here[/url]? | |
Re: Member by member. [url]http://www.eskimo.com/~scs/C-faq/q2.8.html[/url] | |
Re: 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]. | |
Re: Maybe something like this?[code] dptr = iter->second; if(dptr != NULL) { delete dptr; iter->second = NULL; }[/code] | |
Re: 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 … | |
Re: [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] | |
Re: [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) … | |
Re: [url]http://www.cpp-home.com/forum/viewtopic.php?p=36920#36920[/url] | |
Re: >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', ... ? | |
Re: 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 … | |
Re: >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 … | |
Re: [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 … | |
Re: [code]#include <math.h> double degrees_to_radians(double degrees) { double PI = 4.0 * atan(1.0); return degrees * PI / 180.0; }[/code] | |
Re: 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: " << … | |
Re: [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 … | |
Re: [QUOTE=chound]As long it works why do u want to change it?[/QUOTE]Because it is not guaranteed to work in the future. | |
| |
Re: [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 … | |
Re: 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; } /* … | |
Re: [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 … | |
Re: [code]Fraction = 1/n;[/code]Integer division: the result is zero. | |
Re: [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] | |
Re: > 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]? | |
Re: 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 … | |
![]() | Re: [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 … ![]() |
Re: 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]; … | |
Re: If you're using C++, why aren't you using [font=Courier New]std::string[/font]? | |
Re: >`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 … | |
Re: [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] | |
Re: [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] | |
| |
Re: [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] | |
Re: [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 … | |
Re: 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 … | |
Re: 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, … | |
Re: [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 … | |
![]() | Re: 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. |
Re: [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? | |
Re: [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] | |
Re: [url="http://www.eskimo.com/%7Escs/C-faq/q12.26.html"][font=Courier New]fflush(stdin)[/font][/url] | |
Re: [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 … | |
Re: [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; } … | |
Re: [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 … | |
Re: [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? |
The End.