6,741 Posted Topics

Member Avatar for TheSecOrg

How good of a timer are you trying to write? If it's a boo-boo practice exercise or you don't need sub-second granularity, the standard <ctime> library is more than sufficient. Just wrap a few function calls in a class and call it good.

Member Avatar for TheSecOrg
0
248
Member Avatar for tyalangan

>1. What are all the "long" functions for? Do I have to use "long"? They're for the date and time calculations. You don't have to use long, but it helps to avoid integer overflow. >2. (just trying to understand this program) what are your "e"s and "s"s? Poor naming. s …

Member Avatar for Davish
0
279
Member Avatar for joelogs

>aside from that i am not that proficient in c, i'm more into java Last I checked, homework assignments were meant to help you learn the subject matter. Thus, claiming that you aren't proficient isn't exactly a good reason not to try.

Member Avatar for jon.kiparsky
0
1K
Member Avatar for ehsantl

This is one area where arrays and dynamic arrays are different. To pass an actual array as a function parameter, the following syntax is used: [code] T (*param_name)[COLS] [/code] Alternatively, you can use the empty dimension syntactic sugar: [code] T param_name[][COLS] [/code] The first dimension can also hold a size, …

Member Avatar for mrnutty
0
800
Member Avatar for MareoRaft

When you run the program, watch your hands carefully and count how many keys you hit. I suspect you're assuming that the Enter key is somehow treated differently when in reality it too is extracted by getchar as the '\n' character. -38 is fully expected when '\n' is 10 and …

Member Avatar for MareoRaft
0
3K
Member Avatar for CzechRock3

I'm not sure I understand your problem (working with std::string is no less powerful than C-style strings), but if you're ultimately converting to an integer type length [I]should[/I] be a consideration due to overflow.

Member Avatar for CzechRock3
0
403
Member Avatar for EvolutionFallen

[B]>Positive values seem to follow ASCII, but ASCII is only 128 characters. So where are the others from?[/B] It really depends on the character set your system is using, but probably Unicode or some form of extended ASCII.

Member Avatar for EvolutionFallen
0
110
Member Avatar for gaurav_13191

[edit] Doh, this is the C forum. Post replaced. [/edit] The same function you use for single lines, fgets.

Member Avatar for Narue
0
63
Member Avatar for saransh60

[B]>is temporary object created is returned to a2 object ?[/B] Conceptually, yes. In practice compilers can often optimize away return value temporaries. [B]>why it can't be returned by reference?[/B] Well, in this case it can't because then you would be returning a reference to a local object, which is immediately …

Member Avatar for Narue
0
116
Member Avatar for kashifboy

Are you required to update the file with each edit? It's often more practical (barring very large files) to keep the file in memory and work with the copy in memory. Then when a convenient time comes to save the edits, you can overwrite the file. To read the file …

Member Avatar for Narue
0
85
Member Avatar for newbie_to_cpp

[B]>How many years will it take one on avg to master C++ (doing self study) or atleast get a fair touch of this lang?[/B] Mastery is quite different from competence (which is how I interpret "a fair touch"). If you're an experienced programmer you can become competent with C++ in …

Member Avatar for ceriamultimedia
0
102
Member Avatar for ak_2005

>I installed TurboC++ version 3.0 in my computer Okay. >which runs a WindowsXP OS.... It might start without crashing, but a lot of old programs start on Windows XP and don't work correctly due to their age. >The same Turboc++ works well in other computers with the exact configuration as …

Member Avatar for shriniwas
0
5K
Member Avatar for newbie_to_cpp

[B]>Who make better programmers? Men or Women?[/B] Based on my experience conducting interviews, I'd say men make better programmers on average. Of course, that's completely anecdotal with no scientific rigor, so it's worthless as an answer to your question. I'm not aware of any studies on the subject; you'll simply …

Member Avatar for NicAx64
0
110
Member Avatar for harris21

[B]>NO, at least, it would be extremely surprising and weird. Just try and see. I >bet you that if you have a proper compiler, it will issue a compilation error.[/B] If your compiler complains about a pure virtual destructor, either the compiler is non-standard, or your code is wrong. [B]>Why? …

Member Avatar for mrnutty
0
738
Member Avatar for Kakashi Hatake

You're not reassigning the reference, you're overwriting the value of ival, to which ref is a synonym: [code] #include <iostream> int main() { int ival = 12, ival2 = 14; int &ref = ival; ref = ival2; std::cout<< ref <<'\n'<< ival <<'\n'; } [/code] [B]>1 more thing- do references occupy …

Member Avatar for Narue
0
1K
Member Avatar for gaurav_13191

[B]>But I can't understand how p holds the value 30000 or how the result of the program is addition of 30000 and 20..[/B] Presumably this hideous trick is meant to add two numbers without using the + operator. a is converted to a pointer to char, thus making the address …

Member Avatar for Narue
0
197
Member Avatar for boyhenyo

>can you give me a code for queue program??? I can do one better. I'll give you code for a queue and a stack program: [code] #ifndef JDEQUE_H #define JDEQUE_H /* Increment or decrement an index with wraparound */ #define _wrap_decr(i,n) ( (i) = ( (i) == 0 ? n …

Member Avatar for polisure
0
202
Member Avatar for Stefano Mtangoo

[B]>I want its kids to be concrete classes But I don't want to implement the all methods of the class.[/B] Oddly enough we just had a discussion about this. You can make the "optional" member functions simply virtual instead of pure virtual (all with no-op bodies). Then include a pure …

Member Avatar for Stefano Mtangoo
0
130
Member Avatar for harris21

I'll get the bug out the way first: [B]>sample obj(); //explict call only here allow because of explicit keywoed[/B] This isn't a constructor call, it's a function declaration. Remove the parens and you'll construct a new object called obj. While it's still calling the constructor, one could argue that a …

Member Avatar for mrnutty
0
300
Member Avatar for gaurav_13191

[B]>This causes an exception, please explain the error.[/B] Simple, an uninitialized pointer is not a pointer to infinite memory. It's an invalid pointer.

Member Avatar for gaurav_13191
0
109
Member Avatar for darkroad

[B]>Here's a solution that I think has the desired effect, >although perhaps not quite by the means you might expect.[/B] Clever. Though I'm curious how you came up with that solution. Was it intentionally designed from the start, or did you simply notice a pattern while working out a more …

Member Avatar for ananda2007
0
167
Member Avatar for tarakant_sethy

[B]>could anyone give a clear description of memory allocation process when virtualism works.[/B] Obviously this varies from compiler to compiler, but a typical implementation will generate vtables at build time. So when your program is loaded into memory, the vtables are already set up for the inheritance hierarchy. The constructor …

Member Avatar for sanjeevarao
0
88
Member Avatar for EdAtTheAirport

[B]>but that's really programming in C, not C++.[/B] No, it's just a part of C++ that should be considered more advanced due to the lower level nature. The real question is why is a book teaching such things so soon? Most likely it's ignoring the more useful parts of C++ …

Member Avatar for arkoenig
0
200
Member Avatar for Duki

[B]>If tp is going to be altered, like that then why even have getter/setters?[/B] Getters and setters are member functions, you can do more than just get/set a single data member. You can include logging, or debug output without any trouble, whereas if the data members are public/protected, life becomes …

Member Avatar for Duki
0
181
Member Avatar for glenndr_15

How do you get the hello world program wrong? Any decent C++ programmer should be able to type it out flawlessly while plastered from booze, spun around in a chair for ten minutes, and blindfolded. :D

Member Avatar for mrnutty
0
184
Member Avatar for mrnutty
Member Avatar for saanda

Presumably each line is processed individually, in which case you can simply read a line at a time and then parse it. As an example, this program would echo the file to stdout: [code] #include <fstream> #include <iostream> #include <sstream> #include <string> int main() { std::ifstream in("file"); if (in) { …

Member Avatar for mtbs1826
0
20K
Member Avatar for winbatch

>should work on unix as ANSI is listed. _vscprintf isn't a standard C function. It's a Microsoft extension that is unlikely to work on Unix.

Member Avatar for noormanman
0
600
Member Avatar for fedya

[B]>Can someone explain me what does this mean? >"40[^\"], %*c"[/B] Assuming it's actually "%40[^\"], %*c", it means read a string of up to 40 characters or until a double quote is found (%40[^\"]), then match a comma, any amount of whitespace, and ignore the next non-whitespace character (%*c). The %[ …

Member Avatar for uday jha
0
611
Member Avatar for nancy11

[B]>Any one can help me?[/B] Not when your description of the problem consists solely of vague techno-babble.

Member Avatar for Narue
0
91
Member Avatar for timb89

Perhaps it could be because temp is pointing to some random location? Pointers aren't magic, you're responsible for making sure they point somewhere sensible. Since this is C++, I'd also use a constructor to simplify code using termNode: [code] struct termNode { int coeff; int exp; termNode *link; termNode(int coeff, …

Member Avatar for Kanoisa
0
100
Member Avatar for emilio

srand seeds the random number generator. If you call srand too often, and the value you use as the seed (srand's argument) changes infrequently, you'll keep seeding the random number generator to the same thing and rand will produce the same sequence. [url=http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx]This[/url] will give you an idea of how …

Member Avatar for mayur.sarode
0
309
Member Avatar for serkan sendur

Wow, I was [i]just[/i] explaining interfaces to a coworker the other day. Freaky. >Does any one know a robust benefit of using interfaces? Consider the concept of data hiding. Let's say you want to provide a class to some client code, but don't want to give them full access. One …

Member Avatar for Sam.ars
0
1K
Member Avatar for zandiago

Piracy is wrong, period. You can rationalize it with different motives, but in the end you're still refusing to honor the creator's wishes even though they have every right to distribute their creation however they choose. The penalty should be identical to theft. You're punished in a way that's representative …

Member Avatar for jon.kiparsky
2
981
Member Avatar for psionic

>That seems a bit overkill It does at first glance. >why not just cast the character to an integer and add the number then recast back to character? Well, first because there's no need to cast, and second because letters in the basic character set are not required to be …

Member Avatar for srinivasan106
0
365
Member Avatar for zapman2003

[B]>score[i].thescore ->name = n;[/B] Close. [ICODE]thescore[/ICODE] is your dynamic array, not [ICODE]score[/ICODE]: [code] score->thescore[i].name = n; [/code] Apply that logic to your whole program.

Member Avatar for blech
0
108
Member Avatar for Your_mum

[B]>1) Explain why this is used - what are the pros/cons?[/B] That's quite a broad question. Can you be more specific about what you learned and what part of it is confusing? [URL="http://www.eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx"]This[/URL] is a tutorial that I wrote. It's more of an overview of pointers in general, but it …

Member Avatar for Your_mum
0
217
Member Avatar for gahhon

[B]>how can i use the switch statement to find a value in a range?[/B] Short answer: you don't. Long answer: You need a case for each value in the range, which obviously doesn't scale well at all. Use an if..else chain if you want ranges.

Member Avatar for Adak
0
178
Member Avatar for babug

[B]>All we know that PI = 22/7.[/B] Apparently not, because those of us who are correct know that PI < 22/7. Further, because PI is an irrational number there's no combination of x and y where x/y = PI. [B]>But how and why it is 22/7 rather other fractions? [/B] …

Member Avatar for Sriman_Laxmi
0
1K
Member Avatar for rinoa0424

[B]>I am curious how to became a white-hat hacker.[/B] Not many people in the know will trust that your intentions are benign. So my advice is to become a black hat first. Roll with other black hats and learn from them, but don't delve so deeply that you do any …

Member Avatar for Narue
0
218
Member Avatar for vbx_wx

[B]>It outputs 0 when I would expect 2.[/B] The problem is with your expectation. You're punning the bytes of a multi-byte object(float) to raw binary[1], then casting the first byte[2] of the result to another multi-byte type (int) and somehow expecting the value to match what was originally stored in …

Member Avatar for Narue
0
77
Member Avatar for gahhon

[B]>so how does it loop ?[/B] Not false is true, not true is false. That's how boolean logic works. Perhaps if you study equivalent constructs, things will become more clear. The following two snippets do exactly the same thing: [code] while (!correct) { ... } [/code] [code] while (correct == …

Member Avatar for Narue
0
135
Member Avatar for m_ishwar

[B]>Can anyone help me?[/B] Post your code, or a suitable facsimile of your code that exhibits the problem. [B]>Is it a problem with the compiler or my program. The latter is not possible >since I tried out a similar program from a book and got similar results.[/B] It's not possible …

Member Avatar for Aia
0
119
Member Avatar for Codeburner

No, there's no difference, assuming we're talking about the result of the sizeof operator and any assumptions gleaned from it rather than technicalities such as the struct hack.

Member Avatar for Narue
0
82
Member Avatar for kimimaro

>and error still occured pls help You didn't specify what the error was. >I am a girl doing my 1st simple program "Oh great, is Narue going to bash the title now?" Yes. :) First, it's not informative at all. Second, it has useless information. We don't care if it's …

Member Avatar for Adak
0
252
Member Avatar for pamelaanne05

[B]>Help please?[/B] "Help" doesn't constitute doing your thinking for you. It doesn't constitute doing your typing for you either. Until you come up with something besides a program requirement, and thus prove that you're not looking for a handout, you're welcome to piss off.

Member Avatar for soulcandra44
-3
194
Member Avatar for mjmythili

>how do i check the no of elements on the array ? Strings take an character value (the '\0' character) and use it as a sentinel. You can do the same thing with an integer array, but just like with strings, you can't use that sentinel as a legitimate value. …

Member Avatar for Ancient Dragon
0
885
Member Avatar for posche

[QUOTE=firstPerson;]That will be $100 per homework please.[/QUOTE] That's cheap. I use my regular consultancy rates for lazy student homework: $250/hour with a minimum of 8 hours.

Member Avatar for posche
-3
91
Member Avatar for Sesshokotsu

>It violates about every rule in the book (homework, bumping, code tags) [B]Homework[/B]: It's a clause for the person asking questions, not the person answering them. There's no explicit rule saying that you can't give the complete answer to homework (though it is an [URL="http://www.daniweb.com/forums/thread78060.html"]unwritten rule[/URL] and you'll lose face …

Member Avatar for soulcandra44
0
172
Member Avatar for srinath33

>can...u...convert..words..2..no..????? Yes, though the inverse is easier due to formatting constraints. It's not a trivial problem, but it's also not overly difficult. What have you tried?

Member Avatar for soulcandra44
-1
104

The End.