6,741 Posted Topics
Re: The specifier for double with scanf is %lf. %f is for float. Also note that we have a separate forum for C++ questions. This is the C forum. | |
Re: I want you to ask a [URL="http://catb.org/~esr/faqs/smart-questions.html"]smart question[/URL], but apparently neither of us are getting what we want. | |
Re: >plz explain me with syntax "how to pass pointer to a function or pointers to a function " For each level of indirection in the function argument list, add an asterisk. If the argument isn't already a pointer of the same type as the argument list, dereference or add & … | |
Re: [B]>Should I be using fget instead of scanf?[/B] Yes: [code] if ( fgets ( input, sizeof input, stdin ) == NULL ) { /* Handle input error */ } [/code] [B]>scanf( "%c\n", &input[81] );[/B] For the record, input[81] is an invalid index because the size of your array is 81. … | |
Re: [B]>tempStr[0] = va_arg(arg_ptr, char **);[/B] A two dimensional array is not compatible with a pointer to a pointer. Either switch to using an actual pointer to a pointer for your source, or pull the correct type from your varargs list: [code] #include <stdio.h> #include <stdarg.h> #include <string.h> #include <stdlib.h> void … | |
Re: [B]>So if you return -1 its gonna throw exception or what?[/B] -1 is a valid return value, but what it means is implementation-defined. [B]>how is perfectlly normal in java to say public static void main( String args[]) {} ???????[/B] When you design a programming language, you make the rules. It's … | |
Re: Here's one way with sscanf: [code] #include <stdio.h> int main(void) { const char *src = "-6 1 2 3 6"; int pos = 0; int n = 0; int x; while (sscanf(src + pos, "%d%n", &x, &n) == 1) { printf("%d\n", x); pos += n; } return 0; } [/code] | |
Re: [B]>i need to print them out ascending and descending[/B] To sort descending, it's a simple matter of reversing the comparison in your bubble sort function. You can either write a second function, or modify your current one to use a flag passed in as a parameter: [code] void Bubblesort (char … | |
Re: [B]>cin >> length, width;[/B] This doesn't do what you think. A comma is inapproriate, it should be another >> operator: [code] cin>> length >> width; [/code] [B]>cout << " The total cost will be " << areaR << endl; >areaR= (length * width); >cin >> areaR; >cin >> areaR;[/B] This … | |
Re: [B]>I REALLY badly need something of that kind[/B] Perhaps if you describe what you're trying to do, one of us can suggest a solution better suited to C++. | |
Re: The only things [icode]int[/icode] can hold are whole numbers. Any precision you assign to an integer will be truncated. | |
Re: [URL="http://www.cplusplus.com/reference/algorithm/"]C++ reference: <algorithm>[/URL]. The generate and fill families are probably what you want. You can also use the inherited C functions in some cases, but for C++ they're more likely to be dangerous than anything. | |
Re: Your compiler is right: [B]>data[i] != '\0'[/B] Data is an array of System::String. '\0' is a character literal. I'm not sure what you were trying to do here (perhaps compare data[i] to nullptr?), but you could just as easily use the Length property of the managed array type: [code] for … | |
Re: Since you don't know how many objects there will be, a dynamically sized collection is probably the way to go: [code] #include <ctime> #include <ios> #include <iostream> #include <limits> #include <string> #include <vector> int main() { std::vector<std::string> v; char ch; while (std::cin.get(ch)) { std::time_t now = time(0); v.push_back(std::ctime(&now)); if (ch … | |
Re: [B]>fnptr =this->myvurtualfn1(); //error C2440: '=' : cannot convert from 'void' to 'void (__cdecl *)(void)'[/B] [LIST=1] [*]You're not taking the address of the member function, you're calling it. [*]Pointers to member functions are not compatible with pointers to functions. [/LIST] [URL="http://www.eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx#ptrtype"]This[/URL] might help with the syntax issues. | |
Re: Aside from having everything initialized/destroyed for you by the compiler, and hiding the actual dereferencing through convenient syntax, there's really no magic to the vtable method of polymorphism. Just out of curiosity, why are you doing something manually that C++ already supports? | |
Re: buffer[i] es un número entero. No es necesario diferenciar entre decimal y hexadecimal que se imprima el valor: [I]buffer[noparse][i][/noparse] is an integer. You don't need to differentiate between decimal and hexadecimal until the value is printed:[/I] [code] buffer[i] = atoi ( aux ); /* La única diferencia es cómo buffer … | |
Re: [B]>A word I wouldn't expect to see in a programming text >"gauche"[/B] Why not? | |
Re: [B]>As it stands now, I am getting a segfault.[/B] I'm not surprised. You have the right idea in making a copy of the name to return, but you're attempting to return a pointer to a local variable, which is a bad idea. When a function returns, the local variables are … | |
Re: [B]>Recently I replaced the 6.0 with Visual C++ 2008 Express. >Now, none of my older code will compile.[/B] I'm not surprised. One of the biggest things Visual C++ 6 supports that newer versions do not is the prestandard headers: [code] // Compiles in VC++6, but not VC++2008 #include <iostream.h> int … | |
Re: [B]>please help how can i do this[/B] Two easy ways: [list=1] [*]Throw all of the numbers into a better suited data structure (such as an std::map). [*]Sort the array and do some counting. [/list] | |
Re: [B]>I just kinda fiddled with different combinations till I got it to work.[/B] That's called programming by accident, and it means you're no better than an ape pounding at the keyboard. There's no design involved, you run an even higher risk of introducing bugs into code you don't understand, it's … | |
Re: [B]>Dev is quite a good compiler and editor but IMO the debugger...sucks.[/B] Yes, the debugger in Dev-C++ has a bit to be desired. It's actually just a graphical interface into gdb, and not a very good one. [B]>So I would like to know your opinion on Dev[/B] I like it, … | |
Re: [B]>If so, how do I write this constant address?[/B] Cast it to the appropriate pointer type: [code] int *p = (int*)1; [/code] However, it's strongly recommended that you [i]don't[/i] do this unless you really know what you're doing. | |
Re: [B]>need to change this from availcredit01.cpp to availseats01.cpp >and make the necessary adjustments[/B] Well? What have you done to accomplish this requirement, what's the problem that prompted you to post a thread, and how did you attempt to fix the problem before running to us with your tail between your … | |
Re: If you have a question about a specific error, post the error message. If you want to post code, use code tags. [B]>what is a better way too write this without getting an error[/B] Well, seeing as how your syntax is horribly broken, I'd say start by cracking a book … | |
Re: Do you know how to pass an array of pointers to int? It's the same thing, just with a different pointer type: [code] void duh ( int *array[], size_t size ); [/code] | |
Re: [B]>now chk wats wong at line 26 and 34[/B] The same thing that was wrong before: you're trying to write code too far beyond your ability. Start smaller and work your way up. At least then you won't have to rely on other people to hold your hand the whole … | |
Re: Um, there's more to a trie than that. Have you worked with binary search trees before? Tries are a more general tree structure where the number of nodes isn't restricted. | |
Re: [B]>This library is powerful, helpful, and relatively easy >to learn, and it works in all c++ compilers.[/B] Visual C++ 6 has a notoriously broken standard library (especially the STL). But with a few caveats, you're right: [LIST=1] [*]Compilers that were released before or around 1998 may not conform well at … | |
Re: [B]>I suppose you're looking for something like that if i am not mistaken[/B] I can't tell if you're incompetent or simply posting bad code to get the OP a failing grade. | |
Re: [B]>Sorry to harsh, but ...well...you know... it sucks.[/B] It could always be worse. For example, he could be using a variable length array extension instead of [ICODE]new[][/ICODE]. | |
Re: Look up the escape characters for C. You have the option of an octal escape character and a hexadecimal escape character. | |
Re: >iostream is somewhat more restrictive than the older iostream.h. If by "more restrictive" you mean the requirement to qualify the std namespace when using a standard name. iostream is vastly more powerful and flexible than iostream.h and is more fully featured. >iostream.h is deprecated No, iostream.h is [b]gone[/b]. It was … | |
Re: [B]>assign6.cpp:110: error: ‘accountID’ was not declared in this scope[/B] Your compiler is right, accountID was never declared in the cAccountList::sort_by_ID member function. You need to declare a variable before using it. [B]>assign6.cpp:111: error: ‘class cAccount’ has no member named ‘get_accoutID’[/B] Check your spelling. [B]>assign6.cpp:112: error: no match for ‘operator<’ in … | |
Re: [B]>strncpy(mon, m, 2);[/B] Where does mon point? | |
Re: [B]>while(i < N - k) PartSum +=DataArray[i];[/B] [ICODE]i[/ICODE] is never updated in this loop. | |
Re: [B]>Is there any standard rules when we write the main function.[/B] Oddly enough, there are. You have two 100% portable definitions of main: [code] int main ( void ) { /* ... */ } [/code] [code] int main ( int argc, char *argv[] ) { /* ... */ } [/code] … | |
Re: [B]>So what do you love to use when it come to C/C++?[/B] I think love is a strong word for a tool. I like various features of the different IDEs I use, and choose among them based on my needs (if I choose to use an IDE at all). Visual … | |
Re: [B]>Q1: Should I continue studying this even though it could be a bit outdated?[/B] Yes, the Win32 API is still relevant. But be sure to use [URL="http://msdn.microsoft.com/en-us/library/default.aspx"]MSDN[/URL] to keep yourself up-to-date on the latest additions, because as you said, that book [I]is[/I] somewhat old. [B]>Q2: What is the best most … | |
Re: You can supply a predicate to the [URL="http://www.dinkumware.com/manuals/default.aspx?manual=compleat&page=algorith.html#sort"]sort[/URL] template from <algorithm> that does the comparison: [code] #include <algorithm> #include <vector> void sort_object_list ( std::vector<sometype>& object_list ) { struct compare { bool operator() ( const sometype& a, const sometype& b ) { return a.z < b.z; } }; std::sort ( object_list.begin(), … | |
Re: [B]>Do anyone knows how we can implement this code[/B] Yes. [B]>I need a help quickly.[/B] We're not a charity for lazy students. If you want help, you need to do some work yourself first. | |
Re: [B]>using namespace std;[/B] You can remove this line by explicitly qualifying the std namespace on your names. [B]>cin.clear (); >cin.get (); >cout << endl;[/B] These lines are unnecessary. Further, you can merge the input into a single prompt: [code] std::cout<<"Enter two numbers: "; std::cin>> a >> b; [/code] [B]>cout << … | |
Re: [B]>Will this function accomplish that?[/B] Oh, dear. [B]>tmp = (IntSLLNode*)malloc(sizeof(IntSLLNode));[/B] Why are you allocating memory? This function [i]deletes[/i] nodes. [B]>tmp = head;[/B] Bye bye memory. Now you've lost your only pointer to the memory you just allocated. That's what we call a memory leak. [B]>oldTmp = (IntSLLNode*)malloc(sizeof(IntSLLNode)); >oldTmp = tmp;[/B] … | |
Re: [B]>just wanted to learn more.[/B] You might consider learning things that have a chance of being used outside of a classroom setting. Turbo C is pretty much dead except in out-of-date schools and historically interested hobbyists. | |
![]() | Re: [B]Q: what are the different stages in SDLC? Me: Requirement Analysis -> Design -> coding -> Testing -> Implementation and Maintenance[/B] Canned answer to a vague question, not promising at all. I'd expect you to dig for more details before coming up with an answer. For example, which methodology am … |
Re: How do you know it can't open the file? Does your error message print? If so, change it to this for more details: [code] perror ( "Error: file could not be opened" ); [/code] | |
Re: [B]>MultiThreading?[/B] Multithreading, spawn multiple processes, or fake your own threading. The latter isn't recommended for real code, but it can be fun. [B]>Please type the code for this,if you can.[/B] I'm not going to do your work for you, dude. You didn't even say what platform you're running on, which … | |
Re: ofstream opens the file in write mode, which truncates any existing data. You can specify [ICODE]ios::app[/ICODE] as the second argument to ofstream's constructor. This will append without truncating. p.s. I'm not in the mood to beat some sense into you, so I'll let everyone else snipe at your code and … |
The End.