6,741 Posted Topics
Re: Google the "pimpl idiom" (no, that's not a typo) for the usual way in which we hide a class' implementation details. | |
Re: Your hand is generally the best tool for manipulating the mouse. | |
Re: [QUOTE=lelejau;1676518]why dont you use fopen instead?[/QUOTE] What would that accomplish? | |
Re: I don't see the need for nested loops here, just keep a running count: [code] while (fscanf(in, "%d", &number) == 1) { ++n; if (number % 2 == 0) ++even; else { sum += number; ++odd; } } /* Calculate the average... */ /* Display the results */ [/code] | |
Re: [QUOTE]Hope you undestand.[/QUOTE] Not even a little bit. Please rephrase your question. | |
Re: [QUOTE]can some one please give me a brief introduction to pointer...[/QUOTE] A pointer is a variable that holds the address of another object. A pointer can be dereferenced to access the object stored at the address. [QUOTE][CODE]cout<<i (mean to print i)[/CODE][/QUOTE] [ICODE]i[/ICODE] is uninitialized, but yes. [QUOTE][CODE]cout<<*i (what does it … | |
Re: Typo:[ICODE]q-left->parent=pu;[/ICODE] should be [ICODE]q->left->parent=pu;[/ICODE]. In an annoyance you'll encounter many times, the symmetric case has the same problem in the same place because you probably cut and pasted to get it. Another line that raises red flags is this one: [code] while((q->parent->color=true)&&(q->color=true)) { [/code] Did you intend to use assignment? | |
Re: [QUOTE]int mine(int ,int,int);[/QUOTE] Your prototype clearly says that the first argument is [iCODE]int[/iCODE]. Maybe you shouldn't lie to the compiler, it can get confused easily. ;) | |
Re: The assignment operator doesn't play well with the insertion (<<) and extraction (>>) operators. Ideally you would break those expressions out and print the result: [code] meters = miles*YARDS_PER_MILE*INCHES_PER_YARD*METERS_PER_INCH; meters2 = yards*INCHES_PER_YARD*METERS_PER_INCH; meters3 = feet/FEET_PER_YARD*INCHES_PER_YARD*METERS_PER_INCH; meters4 = inches*METERS_PER_INCH; totalmeters=meters+meters2+meters3+meters4; cout <<"Units\t\tValue\t\tMeters\n\n\n"; cout <<"Miles\t\t"<<miles<<"\t\t"<<meters<<"\n\n"; cout <<"Yards\t\t"<<yards<<"\t\t"<<meters2<<"\n\n"; cout <<"Feet\t\t"<<feet<<"\t\t"<<meters3<<"\n\n"; cout <<"Inches\t\t"<<inches<<"\t\t"<<meters4<<"\n\n\n"; cout … | |
Re: [QUOTE=Smeagel13;1675826]And clean them straight after declaration! [CODE]memset(cstring1, '\0', sizeof(cstring1)); memset(cstring2, '\0', sizeof(cstring2));[/CODE][/QUOTE] That's unnecessary if the very next thing you're doing is filling the string (as in gerard's example). It's also usually excessive when you can create a valid string by assigning a null character to the first element: [code] … | |
Re: At the bottom of the thread (after the last post) you'll find a block of text: [quote] Has this thread been answered? If this thread has been successfully resolved, please [U]Mark this Thread as Solved[/U] so that it can be added to our Knowledge Base and help others. Also, posters … | |
Re: [QUOTE]is there any way to check that the standart input is empty or no.[/QUOTE] There's no portable way to do this without actually blocking for input. What OS and compiler are you using, and why do you think you need that behavior? | |
Re: [QUOTE]Came across this showbits() function in the book im using to learn C.[/QUOTE] The code from your book is broken. [ICODE]i[/ICODE] is an unsigned type, which means that it will never be less than 0. Thus the loop is infinite. You can turn [ICODE]i[/ICODE] into a signed type such as … | |
Re: [QUOTE]You cannot declare arrays like that.[/QUOTE] Yes, but only because the OP is clearly not compiling as C99. I can tell because main() uses implicit int, which was removed in C99. [QUOTE] Here either 'n' should be initialized prior to declaring array [CODE] printf("Enter size:"); scanf("%d",&n); int a[n]; [/CODE] [/QUOTE] … | |
Re: [QUOTE]So should i assign 0 value to the remaining elements when i perform an pop operation.[/QUOTE] Unnecessary. The [iCODE]tos[/iCODE] field is what determines where the top of the stack is, and when you push to a spot that's previously been populated, just overwrite the value. However, if you really did … | |
Re: Figure out what the width of the screen is, divide that by 2, then subtract half of the shape's width that you're trying to print. Then before printing each row of the shape, add that many spaces. | |
Re: [QUOTE=Hassan Touqeer;1674869]this is not working in cpp[/QUOTE] Then your compiler doesn't support getch(). That's the risk of using non-portable constructs. If you want help getting it to work, please start a new thread. | |
Re: [QUOTE][CODE]for(i = 0; i <= elements; i++) {[/CODE][/QUOTE] This is an off-by-one error. The last value element is [ICODE]output[elements-1][/ICODE], not [ICODE]output[elements][/ICODE]. [QUOTE][CODE]output[i] = malloc(1000*sizeof(char)); output[i] = names[i];[/CODE][/QUOTE] So you allocate memory, then immediately throw away your only reference to the memory just allocated? That's called a memory leak. Since you … | |
Re: The only problem you have is reading the file. The algorithm for calculating standard deviation is sound. Take a look at this instead: [code] #include <math.h> #include <stdio.h> int main(void) { FILE *in = fopen("test.txt", "r"); if (in != NULL) { int sum = 0, sum_squares = 0, n = … | |
Re: Rather than making common questions stickies onesie-twosie, perhaps you could get some of the PHP regulars to collect frequently asked questions and links to threads with the best answers to those questions into a FAQ thread? That strikes me as a much more useful sticky, and it scales better as … | |
Re: [QUOTE=pbteam08;1630830]The D.B.A. requires coursework and research beyond the masters degree that normally results in a dissertation or journal publication that contributes to business theory or practice.[/QUOTE] You might try actually reading the thread before posting. Or is this an attempt at signature spam? | |
Re: Unless you're doing this to learn about the encodings, I'd recommend using a library that does it for you. I usually recommend [URL="http://site.icu-project.org/"]ICU[/URL]. | |
Re: Welcome to the real world. :) Not to defend bad programmers, but often you'll find yourself divided between writing "bad code" and <insert undesirable business result>. 9 times out of 10, the lesser evil is writing bad code, and that's a harsh reality that newbies need to come to terms … | |
Re: [QUOTE][CODE]void **getxyz() { int **x;[/CODE][/QUOTE] This is a red flag, by the way. While void* is C's generic pointer type which can be implicitly converted to any other pointer type[*], void** doesn't have the same properties. If getxyz() above tries to return [ICODE]x[/ICODE], the compiler will complain about an incompatible … | |
Re: [QUOTE=cvanithakpm;1673766]plz help me to know..whether this pointer in c++ is public access or private access[/QUOTE] Um...what? | |
Re: [QUOTE=Caligulaminus;1673651][ICODE]g_ppStructArray[1][/ICODE] is a [ICODE]ch8_struct[/ICODE], not a [ICODE]ch8_struct*[/ICODE]. So it has to be: [ICODE]g_ppStructArray[1].field1 = 11;[/ICODE][/QUOTE] Close. g_ppStructArray isn't the array, the object pointed to by g_ppStructArray is the array. So you need to dereference g_ppStructArray before any indexing can be done[*]. However, once the indexing is performed on the correct … | |
Re: Polymorphism is a category of programming language features that meet certain requirements[1] and overloading is a member of that category. [1] Specifically: using the same name to refer to and work with different entities in a safe and well-defined manner. | |
Re: You already have a thread [URL="http://www.daniweb.com/software-development/c/threads/388073"]here[/URL]. Please don't start a new thread asking the same question. | |
Re: [QUOTE]Ah! I thought it only works with parentheses.[/QUOTE] If you're using the name of a type, parens are required, otherwise the operand is a unary expression and parens are optional: [code] sizeof(int) /* OK */ sizeof int /* Error */ [/code] [code] int x; sizeof(x) /* OK */ sizeof x … | |
Re: [QUOTE=asif123;1673069]i want to move the cursor of mouse and select the icons using visual c++. i m new to visual c++. can anyone help me plz ?[/QUOTE] Here's an idea: read the thread you're trying to hijack. It has your answer. | |
Re: [QUOTE]What am I doing wrong?[/QUOTE] You're expecting int to have no limits. Let's assume the most likely scenario: you're using 32-bit integers. The largest signed value for int will be approximately 2147483647. The largest unsigned value doubles that to approximately 4294967295. In neither case can a 32-bit integer type hold … | |
Re: [QUOTE]I want to show them like a float[/QUOTE] To what end? You can't add precision that's not there. | |
Re: You're printing the value with %d, which is limited to signed int. The C99 specifier for unsigned long long is %llu: [code] #include <stdio.h> int main(void) { unsigned long long int cnt; for (cnt = 0; cnt <= 4026531840; cnt++) printf("%llu\n", cnt); } [/code] | |
Re: [QUOTE][CODE]fscanf(inputFile,"%d\n");[/CODE][/QUOTE] This is wrong. Whether you plan on using the value or not, it has to be stored in an object: [code] fscanf(inputFile, "%d", &ip); [/code] However, you [i]can[/i] tell fscanf() to throw it away with a modification to the specifier: [code] fscanf(inputFile, "%*d"); [/code] Finally, don't put '\n' in … | |
Re: Both are wrong and invoke undefined behavior. You should be calling _exit(0) because it doesn't perform any cleanup in the child, it just ends the process. Since vfork() shares process memory between parent and child, letting the child perform process cleanup is a Bad Thingâ„¢. Technically, the way you're using … | |
Re: [URL="http://catb.org/~esr/faqs/smart-questions.html"]How to ask questions the smart way.[/URL] | |
Re: Looking at the code you've given, I can tell you straight away that you're not using malloc() correctly. However, I'm having difficulty figuring out exactly what you're trying to do. The variable names (eg. matrices, new_matrix) suggest you're storing multiple two-dimensional matrices of varying size. In that case your types … | |
Re: Visual C++ 2010 doesn't support the current rules for rvalue references (specifically the allowance for implicit conversions). The way to do it presently in 2010 is by creating a temporary rvalue string object: [code] test_rr(std::string("this is")); [/code] Visual C++ 2011 supposedly supports the current rvalue reference rules. | |
Re: So what's stopping you from trying to convert this simple program yourself? | |
Re: Threads merged. | |
Re: If you copy the contents of a text file into a binary file, the text isn't magically going to become unreadable. I think your expectations are misplaced and the code is probably working fine. Though it's hard to say for sure since you've hidden all of the data behind the … | |
Re: [QUOTE=gourav1;1669215]my problem is highly conceptual problem. when i write: node *new1=malloc(sizeof(node)); it works properly. but when i write : node *new1=malloc(sizeof(node*)); it starts giving errors. // node is the structure having a integer and pointer to itself.[/QUOTE] If [ICODE]sizeof(node) > sizeof(node*)[/ICODE] then you'll have problems because you're allocating less memory … | |
Re: Are you required to display the tree like that? Because if not, it's [I]much[/I] easier to rotate the tree by 90 degrees: [code] public void TreeStructure(Node root) { TreeStructure(root, 0); } private void TreeStructure(Node root, int depth) { if (root == null) { for (int i = 0; i < … | |
Re: [QUOTE]now I'm guessing it's because scanf("%d") can't read floating point numbers[/QUOTE] Good call. %f doesn't work either because scanf() is expecting a pointer to float and you pass a pointer to a double. Use %lf for reading doubles with scanf(). [QUOTE]this is a c++ forum. this is not a c … | |
Re: I use my iPad to visit Daniweb occasionally, but posting is a bit of a chore. | |
Re: Your post makes no sense at all. When asking a question, please keep in mind that we're not psychic. | |
Re: csv is a specialization of txt in that the text format is specific to comma separated fields with optional quoting rules for embedded commas. I'm guessing your code simply doesn't recognize the CSV format correctly. How about posting a small example of the CSV file? ![]() |
The End.