1,296 Posted Topics
Re: Apart from anything else this useless macros must be [code=c++] #define FOR(x,n)for(typeof(x)x=0;x<(n);x++) [/code] | |
Re: That's trim w/o side effect (spaces condensing): [code=c] char* trim(char* str) { if (str) { char *ibuf = str, *obuf = str, *sbuf = str; while (isspace(*ibuf)) ibuf++; while (*ibuf) { *obuf++ = *ibuf; if (!isspace(*ibuf++)) sbuf = obuf; } *sbuf = '\0'; } return str; } [/code] I think … | |
Re: >Apparantly the size_t is typedefed to a unsigned long int on my system. Is this safe to assume its the same on all c++ compilers? Nope: "The value of the result (of the operator sizeof) is implementation-defined, and its type (an unsigned integer type) is size_t, defined in <stddef.h> (and … | |
Re: Allow me to have a share in this entertainment: [code=cplusplus] union { int i; char c; } trick[2]; cout << &1[trick].c - &0[trick].c << endl; [/code] Any pointer to int casting is implementation-defined. No guarantee that [code=cplusplus] int a[2]; (int)&a[1]-(int)&a[0] == sizeof(int) // also may be false: (int)&a[1] > (int)&a[0] … | |
Re: Better use double type to calculate factorials. Don't take the risk of integer overflow w/o any signals and with very strange results... | |
Re: Of course, it's a wrong code. You assign a pointer (?) value to the [b]local[/b] variable currentPtr. In other words, do nothing. However it's unclear what is cPtr type. You declare it as a pointer to CategoryPtr. Why CategoryPtr? Is CategoryPtr type a pointer? If so, cPtr is a pointer … | |
Re: What's a problem? Use [icode]double fabs(double)[/icode] from <math.h>. | |
Re: As far as I know it's [icode]scprintf(const char*,...)[/icode] in C99 counts the length of a formatted string (and it's not legal to pass null pointer to sprintf family functions). May be, I'm wrong?.. | |
Re: No standard functions to scan directories. On Windows use FindFirstFile/FindNextFile API, for example: [code=c] #include <windows.h> #include <string.h> void DirScanStub() { const char dirName[] = "c:\\temp\\"; const char dirScan[] = "c:\\temp\\*.*"; char* pname = 0; /* File name buffer */ WIN32_FIND_DATA info; HANDLE h = FindFirstFile(dirScan,&info); if (h == INVALID_HANDLE_VALUE) … | |
Re: Simply define your own random function with same functionality as Borland random: [code=c] int random(int n) { return rand() % n; } [/code] That's all. | |
Re: You include stack.cpp before and after template definition ;) | |
Re: 1. It's impossible to overload basic types operators, so don't try to overload an addition op for [b]float[/b] total and average... 2. You may overload operators for your class Statistics (in other words, to define operators with class Statistic arguments), but what's an example of a reasonable operator of a … | |
Re: It's freeware in the public domain. Try this, it works: [code=c++] struct Cry { const char* what() const { return "Mummy, I'm afraid!"; } }; void Lots() { 2*2==4; throw Cry(); } void of () { Lots(); } void functions () { of(); } int main() { try { functions(); … | |
Re: Yes, old good (or most likely bad) VC++ 6.0 can't compile String member template from std_lib_facilities.h. However why [icode]#include "iostream"[/icode] instead of <iostream>? Better try to download and install VC++ 2008 Express (or Code::Blocks with MinGW/gcc compiler)... | |
| |
Re: May be it helps (see modf function: split integer and fractional parts): [code=cplusplus] /** * 2008-10-01 Beta version. No warranties... * Rounding functions freeware mini-package. * About rounding forms and MS rounding stuff * see http://support.microsoft.com/kb/196652 * Dependencies: <math.h> <float.h> * Languages: standard C and C++ * Not optimized!.. */ … | |
Re: That's just the point: a STL iterator is not an index value. It looks like an index value (via incr/decr overloaded operators) but it's not a number. The std::vector container (or std::valarray or std::string) has integer index values for its elements via overloaded subscript operator but std::map (or std::set) container … | |
Re: [code=cplusplus] // #include <windows.h> in stdafx.h (VC++) struct CurPos { CurPos():x(-1),y(-1) {} int x, y; operator bool() const { return x >= 0 && y >= 0; } }; CurPos getCursorPos() { CurPos pos; CONSOLE_SCREEN_BUFFER_INFO con; HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE); if (hcon != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hcon,&con)) { pos.x = con.dwCursorPosition.X; … | |
Re: Small addition. Question: how will I know when I have the need to do this: [code=cplusplus] double pi = 3.14159265358; [/code] Answer: YOU know when and why... It's the same case. Also you are using copy constructor implicitly when you pass an object as a function argument by value (it's … | |
Re: At first have a look at [icode]return n[/icode] in the newton function ;).. Small coin: 1. Add input check up code. If the user type not-a-number you can't detect failed cin state now... 2. Why not [icode]while (abs(x) > error && n <= nmax)[/icode]?.. Simple and clear... 3. Use typedef … | |
CPU Performance Counter based clock and stop-watch classes for Win2K++ were implemented in VC++. Details: see sources (I hope, these classes, especially StopWatch, have well-to-do interfaces;)). Warning: no special precautions for multi-threading/multi-core CPU environment. It's not so hard work to translate these codes in C (or other C++ implementations). This … | |
Re: Try DISLIN: [url]http://www.mps.mpg.de/dislin/[/url] It's free for non-commercial use. | |
Re: Of course, you can't access protected method in main! Only member functions of derived classes can access protected members. Re-read your C++ textbook... | |
Re: [QUOTE=|\|asrin;869888]Hi I want to have a n*n matrix is there sombody to help me?? how i can write it??[/QUOTE] Start from this forum announcement: [url]http://www.daniweb.com/forums/thread78060.html[/url] (especially [i]Describe your problem clearly and fully![/i] paragraph). | |
Re: >...because if you just put a and b without quotes, the compiler will think that you are using the variables a and b. That's exactly what OP intends to do ;) | |
Re: 1. About C4716: didn't you know that [icode]double F_Ite()[/icode] function [b]must[/b] return double type value? And where is [icode]return anything-of-double_type[/icode] in the function body? It's your code, you have wrote [icode]double F_Ite()[/icode]... 2. Use code tag with the language specifier (see this forum announcements): [noparse][code=cplusplus] source [/code][/noparse] It's impossible to … | |
Re: I have found this exotic Number_1_C... panopticon at Ohio state university site. It looks like an attempt to convert the C++ language to an incomprehensible slang for dedicated persons. As far as I could judge it's not so easy to understand lots of special conventions, mysterious macros and other tricks … | |
Re: Don't worry, it's a small code ;) Try to split functions into separate groups by themes (as usually, it's possible to do). Place every group in a separate cpp file (don't forget to add it to the project). Move all functions prototypes into .h file and include it in every … | |
Re: It's not an error at all. It's a simple info message. Fill the difference. | |
Re: Apropos, your fix_name is wrong. It does nothing (except memory leak). You modify dynamically allocated copy of the string argument then assign the pointer to the parameter (but not to the argument) - that's all. Now you have a memory leak (tmp is not deallocated) and the call argument is … | |
Re: The most natural place for structures without tags is typedef declaration ([i]it's the only place I've used anonymous structs[/i] ;)): [code=c] typedef struct { ... } Record; ... Record rec; Record* prec = &rec; ... [/code] Of course, it's impossible to define self-referential structures in a such manner. Yet another … | |
Re: In C you can assign void* type pointer value to the pointer of any type without casting. So simply declare a proper type pointer and set it to the buffer: [code=c] char* pchar = buf_ptr; char* ptr = pchar + 20; ... ...pchar[20] the same as *ptr... [/code] It's impossible … | |
Re: No a proper constructor of the class SipDialogPublish. Check up class SipDialogPublish definition and types of constructor arguments in the line #343. Probably this constructor was declared but not defined yet... Posted code is irrelevant. | |
Re: Yet another tip: [code=cplusplus] while (infile) // wrong loop! { getline(...); ... >> ... i++ } [/code] See what happens if the file is empty or after the last line reading: 1. infile is good so the next loop entered... 2. getline failed, all subsequent input operations are suppressed... 3. … | |
Re: >[i]I have found lots of ways to do this if I want all of the elements of the string but not how to do it when I only want certain parts.[/i] What's a funny statement... If you can get [b]all[/b] elements (by the way, where is your code?;)), it's so … | |
Re: Of course, it's not a stupid question but it's impossible to answer in a few words. Look at [url]http://www.is.pku.edu.cn/~qzy/cpp/vc-stl/templates.htm[/url] [url]http://www.codersource.net/codersource_cppprogramming.html[/url] | |
Re: Try to adopt this improvisation: [code=cplusplus] const size_t allbut = std::numeric_limits<int>::max(); bool overStep(std::istream& in) { char c; while (in.ignore(allbut,'S')) { do if (in.get(c) && c == 't' && in.get(c) && c == 'e' && in.get(c) && c == 'p' && in.get(c) && c == ' ' && in.get(c) && c … | |
Re: Fill a glass with water (or what else) then drink, not vice versa ;) Calculate a circle area AFTER its diameter request. Output the area variable, not a wrong character literal 'area'... | |
Re: Look at DISLIN (free for personal use): [url]http://www.mps.mpg.de/dislin/[/url] | |
Re: The wittingly wrong statement in OP code is [icode]delete buffer;[/icode] - must be [icode]delete[]buffer;[/icode]. Yet another defect: insufficient error check-up. [code=cplusplus] long GetFileSize(ifstream &file) { static const streamoff badPos(-1); if (!file) // test added return -1; streamoff temp = file.tellg(); if (temp != badPos && file.seekg(0L, ios::end)) { streamoff end … | |
Re: Well, your program crashed. It looks like a mere assertion, not a question. Read This Before Posting: [url]http://www.daniweb.com/forums/thread78223.html[/url]. Never send exe files in attachments! | |
Re: After that place [b]all[/b] system header includes in StdAfx.h (and remove them from .cpp files (after [icode]#include "StdAfx.h"[/icode])... | |
Re: What a wonderful teleportation of argv[3] to every class Path object do you want? If you have a "default" starting point of the Path object (probably it's the scArg member), provide this class for a correspondent constructor or default starting point setting member function - that's all. | |
Re: Better use std::string class: [code=cplusplus] #include <iostream> #include <string> using namespace std; ... string day; ... getline(cin,day); if (day == "Mo") ... [/code] To compare C-style strings use strcmp function from <cstring> header: [code=cplusplus] if (strcmp(day,"Mo") == 0) ... [/code] Now in [icode]day == "Mo"[/icode] you compare pointers (not contents). … | |
Re: Look at LiveGraph (freeware in Java, possible out-process using): [url]http://www.live-graph.org/[/url] and Dislin (free for non-commercial use only): [url]http://www.mps.mpg.de/dislin/[/url] | |
Re: Are you sure that your method is not efficient? Why?.. What's your [i]efficiency[/i] criterion? | |
Re: The 1st version was wrong on Windows, Linux or elsewhere. It returns a pointer to deallocated memory of local string data buffer. The 2nd version works but it's a very dangerous (error-prone) approach to return a pointer to dynamically allocated (by non-standard function strdup) memory. It's so easy to get … | |
Re: See what a class of that sort (std::string surrogate) must have: [code=cplusplus] class Testing { public: Testing(); Testing(const char*); Testing(const Testing&); // copy constructor Testing& operator=(const Testing&); // assignment ~Testing(); ... const char* getName() const { return pName; } void setName(const char* pname); ... private: char* pName; }; [/code] | |
Re: Right direction but lots of defects in OP code. The OP title does not bear a relation to the real OP problems. Think about: [code=cplusplus] // Never fix array size in a function! int getLargest(const int* a, int n) { int largest = 0; if (a && n > 0) … | |
Re: There is a very strange syntax construct in your code: [code=cplusplus] switch (dom_destination) do { case 1: [/code] Of course, it's an error, but syntactically switch statement in C and C++ looks as follows: [code] switch (condition) statement [/code] Now you have a switch with do-while loop body: [code] switch … |
The End.