6,741 Posted Topics

Member Avatar for vict1

Google the "pimpl idiom" (no, that's not a typo) for the usual way in which we hide a class' implementation details.

Member Avatar for vijayan121
0
156
Member Avatar for asif123
Member Avatar for Narue
0
147
Member Avatar for aFg3

[QUOTE=lelejau;1676518]why dont you use fopen instead?[/QUOTE] What would that accomplish?

Member Avatar for Narue
0
192
Member Avatar for neveragn

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]

Member Avatar for neveragn
0
139
Member Avatar for ZedChu

[QUOTE]Hope you undestand.[/QUOTE] Not even a little bit. Please rephrase your question.

Member Avatar for WaltP
0
148
Member Avatar for Majestics

[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 …

Member Avatar for Narue
0
118
Member Avatar for nchy13

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?

Member Avatar for Narue
0
577
Member Avatar for minhviet93

[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. ;)

Member Avatar for WaltP
0
222
Member Avatar for Labdabeta
Member Avatar for Aghtar

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 …

Member Avatar for Aghtar
0
171
Member Avatar for theofilos93

[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] …

Member Avatar for hkdani
0
286
Member Avatar for Heinz Stapff

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 …

Member Avatar for Heinz Stapff
0
345
Member Avatar for vedro-compota

[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?

Member Avatar for hkdani
0
6K
Member Avatar for Aman6o

[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 …

Member Avatar for cse.avinash
0
1K
Member Avatar for challarao

[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] …

Member Avatar for challarao
0
374
Member Avatar for hszforu

[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 …

Member Avatar for hszforu
0
138
Member Avatar for avani20391

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.

Member Avatar for avani20391
0
868
Member Avatar for deepak1331

[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.

Member Avatar for Narue
0
10K
Member Avatar for fishman6

[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 …

Member Avatar for Narue
0
166
Member Avatar for MrNo

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 = …

Member Avatar for D33wakar
0
1K
Member Avatar for cwarn23

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 …

Member Avatar for WaltP
0
174
Member Avatar for nyadimo
Re: DBA

[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?

Member Avatar for Smeagel13
0
125
Member Avatar for anjoz

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].

Member Avatar for reconx86
0
220
Member Avatar for Aman6o
Member Avatar for stereomatching

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 …

Member Avatar for stereomatching
0
250
Member Avatar for Panathinaikos22

[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 …

Member Avatar for Panathinaikos22
0
121
Member Avatar for cvanithakpm

[QUOTE=cvanithakpm;1673766]plz help me to know..whether this pointer in c++ is public access or private access[/QUOTE] Um...what?

Member Avatar for gerard4143
0
119
Member Avatar for maybnxtseasn

[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 …

Member Avatar for Caligulaminus
0
75
Member Avatar for newcountry

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.

Member Avatar for Netcode
0
530
Member Avatar for Se7Olutionyg

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.

Member Avatar for Narue
0
173
Member Avatar for Se7Olutionyg

[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 …

Member Avatar for Narue
0
405
Member Avatar for giora88

[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.

Member Avatar for Narue
0
270
Member Avatar for ToweyLeake

[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 …

Member Avatar for ToweyLeake
0
115
Member Avatar for sasho648

[QUOTE]I want to show them like a float[/QUOTE] To what end? You can't add precision that's not there.

Member Avatar for sasho648
0
346
Member Avatar for jen140

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]

Member Avatar for jen140
0
187
Member Avatar for Zssffssz
Member Avatar for Narue
0
63
Member Avatar for linhj

[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 …

Member Avatar for linhj
0
3K
Member Avatar for Efficience

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 …

Member Avatar for Efficience
0
296
Member Avatar for namratag

[URL="http://catb.org/~esr/faqs/smart-questions.html"]How to ask questions the smart way.[/URL]

Member Avatar for Narue
0
46
Member Avatar for DmytriE

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 …

Member Avatar for Narue
0
95
Member Avatar for stereomatching

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.

Member Avatar for stereomatching
0
286
Member Avatar for dan1992

So what's stopping you from trying to convert this simple program yourself?

Member Avatar for hkdani
0
104
Member Avatar for JOSED10S
Member Avatar for Himajin Breaker

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 …

Member Avatar for Himajin Breaker
0
420
Member Avatar for gourav1

[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 …

Member Avatar for gourav1
0
161
Member Avatar for c++_fem

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 < …

Member Avatar for Narue
0
363
Member Avatar for xocpnytsirhc

[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 …

Member Avatar for xocpnytsirhc
0
182
Member Avatar for jingda

I use my iPad to visit Daniweb occasionally, but posting is a bit of a chore.

Member Avatar for cwarn23
0
198
Member Avatar for vishwanath.m

Your post makes no sense at all. When asking a question, please keep in mind that we're not psychic.

Member Avatar for Narue
0
149
Member Avatar for toneranger

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?

Member Avatar for MonsieurPointer
0
245

The End.