6,741 Posted Topics

Member Avatar for Amr ElGohary

[QUOTE]I wants to know the code ??[/QUOTE] No. Read [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]the rules[/URL].

Member Avatar for WaltP
0
149
Member Avatar for cppgangster

[QUOTE]swscanf_s only keeps reading the same word "šešios" ...[/QUOTE] Because pBuffer doesn't change. Unlike a file stream where the get pointer is managed for you, the scanf family works with a pointer to char and [i]you[/i] must manage moving the pointer around to suit your needs. For example: [code] #include …

Member Avatar for Narue
0
155
Member Avatar for sungod000

[QUOTE]It is a back-end web platform solution for a specific industry.[/QUOTE] That's such a helpful description. :icon_rolleyes:

Member Avatar for BitBlt
0
244
Member Avatar for ThrustinDuffman

[QUOTE]How do I go about detecting when the user enters anything but these numbers?[/QUOTE] There are a number of ways, but none of them are the one-liner that everybody wants. ;) However, the pattern for managing input and covering the cases for each option is fairly straightforward and consistent: [code] …

Member Avatar for Narue
0
92
Member Avatar for ankit.4aug

[QUOTE]because we are pre-incrementing y[/QUOTE] No, you're not. The || operator is short circuited, which means the ++x part evaluates to true and terminates the expression. z is assigned a true value (1), and y doesn't get updated because that half of the expression wasn't evaluated. Consider if ++x evaluates …

Member Avatar for arkoenig
0
201
Member Avatar for Trustify
Member Avatar for Trustify
0
163
Member Avatar for VernonDozier

[QUOTE]Changing the order a bit seems to do the trick. Works now.[/QUOTE] It works for the same reason that prototypes work the way they do. If you have a using directive, it applies to everything below the directive, but not above it. Here's an example that takes advantage of this …

Member Avatar for VernonDozier
0
1K
Member Avatar for marrkee
Member Avatar for vivosmith

The only syntax error I get with a copy/paste of your code is different characters for " than my compiler was expecting. Try the following: [code] #include <stdio.h> int main() { char name[20]; char color[20]; printf("What is your name?"); scanf("%s",name); printf("What is your favorite color?"); scanf("%s",color); printf("%s's favorite color is …

Member Avatar for Narue
0
316
Member Avatar for ghost_from_sa

[QUOTE]The section Below is what i Have so far but im almost 100% certain I'm overlooking something important[/QUOTE] What exactly is the point of your wheels function? Aside from returning a default constructed object of Wheel in all cases, you don't use the Wheel class at all. Essentially all you're …

Member Avatar for ghost_from_sa
0
191
Member Avatar for fadi_1234

You want a random selection. There are a few ways, but storing those items in a container for random indexing is by far the simplest: [code] #include <array> #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { srand((unsigned)time(nullptr)); array<int, 3> a = {11, 22, 33}; cout<<"Random element: …

Member Avatar for mrnutty
0
137
Member Avatar for predator78

[QUOTE]I have hear many opinions that C is not necessary or even prefered if you are going the route of C++.[/QUOTE] If you want to learn C++, learning C first is silly. If you want to be a well rounded programmer, learning C at some point is a good idea. …

Member Avatar for predator78
0
151
Member Avatar for Sonia11
Member Avatar for mike_2000_17
0
173
Member Avatar for Rocker Gang

The implementation depends on your compiler. But the basic idea is that the compiler knows about types such that it can create a type_info instance for each unique type and return a reference to that instance when you use typeid.

Member Avatar for mike_2000_17
0
156
Member Avatar for stereomatching
Member Avatar for bpushia

The last post before yours was from 2007, erbay. I get that you want to show of...whatever that was, but keep in mind that resurrecting old threads isn't something that should be done lightly because it brings that old thread to the front of the list at the cost of …

Member Avatar for Narue
0
6K
Member Avatar for prvnkmr194

The code uses outdated and potentially dangerous techniques, and isn't robust at all. You can easily invoke undefined behavior by typing enough digits to overflow the signed int type. Further, it doesn't properly handle negative values. To improve the code I'd offer three pieces of advice: [list=1] [*]Support the full …

Member Avatar for TrustyTony
-1
285
Member Avatar for programing

Unless you have the dumbest stack ever written, it should be possible to retrieve the top before popping it (or the pop operation returns the removed top). Take that value and pop it onto the other stack.

Member Avatar for TrustyTony
0
136
Member Avatar for IwalkAlone

>It's a bug in scanf(), you shouldn't use it. It's not a bug in scanf, it's a bug in the code that uses scanf. But I do agree that if you don't know how to use something, you shouldn't use it until you do.

Member Avatar for lokeshg
0
2K
Member Avatar for wdearth

How do you get the length of an entered string using only stdio.h functions? Here's one option: [code] #include <stdio.h> int main(void) { char buf[21]; int n, ch; while (scanf("%20[^\n]%n", buf, &n) == 1) { /* Extract and discard the trailing newline and any leading extraneous characters */ do ch …

Member Avatar for TrustyTony
0
169
Member Avatar for wildplace

Graphs are typically implemented with an adjacency list or adjacency matrix (google it). If you're feeling especially frisky you can create the graph directly using linked nodes, but that's not necessarily recommended except as an exercise.

Member Avatar for wildplace
0
108
Member Avatar for porschedream

[QUOTE]however in the name character string an unwanted "," also appears[/QUOTE] Perhaps you should post an example of the string being tokenized and explain exactly what parts you need. :icon_rolleyes: [QUOTE]I do not understand why you are trying to tokinize NULL pointer.[/QUOTE] Then perhaps you should read the link you …

Member Avatar for TrustyTony
0
874
Member Avatar for Pro2000

An unverified user is one who hasn't yet confirmed their registration from the automated email. Since you likely don't have that email from 2007, I'll see about getting that resent to you.

Member Avatar for Pro2000
0
126
Member Avatar for stereomatching

Might I suggest looking at the assembly output for your code? You might be enlightened as to what the code generator is doing. :)

Member Avatar for stereomatching
0
132
Member Avatar for theguitarist

What you've heard is true for some employers. For others it's the exact opposite. Just like any field there are good jobs and bad jobs, you just have to find the one that fits you best.

Member Avatar for theguitarist
0
146
Member Avatar for yashsaxena

[QUOTE]Declaration means ===> where the variables are declared and no memory is allocated.[/QUOTE] From the view of variables only, that's reasonable. An object declaration states the type and name of the object, but does not necessarily cause storage to be allocated for it. A declaration is more of a statement …

Member Avatar for nezachem
0
131
Member Avatar for tubby123

Neither of your programs are correct. In the first you're passing an uninitialized pointer to gets. Uninitialized pointers are [I]not[/I] pointers to infinite memory. In the second you're passing a pointer to a string literal to gets. String literals may be placed in read-only memory, and trying to modify them …

Member Avatar for rubberman
0
138
Member Avatar for shanki himanshu

You can pass the name of the caller into the callee: [code] void a(const char *caller) { printf("%s called from %s\n", __func__, caller); } void b(const char *caller) { printf("%s called from %s\n", __func__, caller); a(__func__); } int main(void) { b(__func__); return 0; } [/code] The above code uses C99's …

Member Avatar for rubberman
0
234
Member Avatar for Labdabeta

Presumably you mean using Obj2 in the typedef despite it not being declared yet. You can forward declare the class to remove syntax errors: [code] class Obj2; typedef Obj2*(*Reaction)(); [/code]

Member Avatar for Labdabeta
0
93
Member Avatar for cse.avinash

Without getting into the serious issues of your code, the problem is scanf leaving a newline in the stream. gets terminates on a newline, which means it will terminate successfully right away. The most naive solution uses a call to getchar after scanf to eat that newline: [code] scanf("%d",&n); getchar(); …

Member Avatar for Narue
0
118
Member Avatar for tubby123

Turbo C doesn't support bool as a data type unless you define it yourself. If you get a C99 compiler you can do what you want: [code] #include <stdio.h> #include <stdbool.h> int main(void) { bool a[10] = {true}; printf("Hello, world!\n"); // In C99 omitting the return statement is no longer …

Member Avatar for Narue
0
118
Member Avatar for choboja621

The standard equivalent of [ICODE]flushall()[/ICODE] is [ICODE]fflush(0)[/ICODE]. The only thing flushall does is call fflush on all open streams, which is a feature that fflush already supports by passing a null pointer. There's one caveat though. On implementations where flushall is supported, it typically "flushes" input streams too, where the …

Member Avatar for Narue
0
130
Member Avatar for tubby123

[QUOTE]1)What is the expected output ?[/QUOTE] Nothing. You return before printing any output. [QUOTE]2)I tried compiling this and i dont get anything on the screen[/QUOTE] Yes, that's what I'd expect. [QUOTE]3)In case it returns, then, a)who is calling main ? (is it some systems call or something)[/QUOTE] The C runtime …

Member Avatar for Ancient Dragon
0
151
Member Avatar for n0de

Let's analyze the error. We know that the error is coming from pentathlete_team::operator+, and that there's an issue in calling the results() member function (which is inherited from pentathlete, though that's irrelevant to the issue). [B]>passing 'const pentathlete_team' as 'this' argument discards qualifiers[/B] It's pretty obvious that results() doesn't take …

Member Avatar for n0de
0
1K
Member Avatar for shazzy99

At a glance, the following raises a red flag: [CODE] else //countc++; // do nothing i++;[/CODE] Since you've commented out the body of the else statement, the [iCODE]i++;[/iCODE] statement becomes the body. So you only increment [iCODE]i[/iCODE] when all of the other cases fail. That pretty much guarantees an infinite …

Member Avatar for shazzy99
0
143
Member Avatar for asrockw7

A proper timer will put the thread to sleep and allow context switching. Your naive timer doesn't release the thread and simply eats up CPU cycles doing nothing. This is precisely why the busy wait style of timing is undesirable. There's not really a good way to efficiently use time …

Member Avatar for TrustyTony
0
168
Member Avatar for tubby123

[QUOTE]Logically speaking , you should be able to put a clrscr() anywhere right ?[/QUOTE] Like here? [code] void foo(void) { /* ... */ } clrscr(); int main(void) { /* ... */ } [/code] Or what about here? [code] struct foo { int x; clrscr(); int y; }; [/code] What's your …

Member Avatar for Narue
0
145
Member Avatar for rEhSi_123

[QUOTE]Can I use fread to perform this task?[/QUOTE] Yes, but I suspect fscanf is what you want: [code] int value; if (fscanf(f, "%d", &value) == 1) { /* Successfully read an int value */ } [/code]

Member Avatar for rEhSi_123
0
84
Member Avatar for Anark10n

[QUOTE]the .h files are linked automatically.[/QUOTE] Headers aren't linked at all. Do you know about the primary phases of compilation? [list=1] [*][B]Preprocessor[/B]: Preprocessing directives are evaluated and textually replaced within the source code. Header files are expanded, macros are replaced, etc... The result is a translation unit. [*][B]Compiler[/B]: Translation units …

Member Avatar for Anark10n
0
2K
Member Avatar for jk09

[QUOTE]Average case of building a tree is O(lg n)[/QUOTE] You mean O(N logN). Inserting one item into a tree is logarithmic (excluding degenerate cases), but you want to add N items. [QUOTE]So, can this technique be used over others like mergesort , quicksort etc. where the avg case is O(n …

Member Avatar for Narue
0
99
Member Avatar for gayansameera
Member Avatar for gayansameera
0
103
Member Avatar for Markmit

[QUOTE]I confused why a valid pointer might not be dereferenced[/QUOTE] It's a valid pointer alone, not a valid array element. This gives compilers the freedom to always implement one past the end as a single byte (the smallest addressable unit) and not waste space creating a full unused element of …

Member Avatar for yashsaxena
0
877
Member Avatar for wdearth

Educated guess: [iCODE]scanf("%d",a)[/iCODE] is missing the address-of operator on [iCODE]a[/iCODE]. Often this results in a miserable crash, and it's very easy to forget that it should be [iCODE]&a[/iCODE].

Member Avatar for arjunpk
0
163
Member Avatar for oalee

[QUOTE]everything seems bizaarely diffent from how it looked like ages ago...[/QUOTE] There have been lots of changes over the years, improvements for the most part. Welcome back! :)

Member Avatar for jingda
1
139
Member Avatar for eskimo456

If we're only talking about pass by reference vs. pass by value, then the benefit of pointers only shows up in two cases: [list=1] [*]You want to use output parameters rather than input parameters. Passing by reference enables this. [*]The pointed-to object is relatively large compared to a pointer. [/list] …

Member Avatar for eskimo456
0
404
Member Avatar for gayansameera

What have you done so far? We're not going to help you by doing it for you, but we'll be glad to help with any issues when you prove that you've make some kind of honest attempt.

Member Avatar for gayansameera
0
186
Member Avatar for AliRaiz

Start by determining what your base case is. You have two of them: [list=1] [*]str2 is matched in str1 [*]str2 is empty [/list] Once you have the base cases you can return the appropriate result, and then for any non-base case simply return the result of your recursive call: [iCODE]return …

Member Avatar for AliRaiz
0
97
Member Avatar for harinath_2007

You realize that captcha is designed to thwart OCR engines, right? Tesseract in particular is pretty weak as an OCR engine and would likely have an extremely poor read percentage on all but the worst of captchas. The only thing going for it is being open.

Member Avatar for Narue
-1
129
Member Avatar for cresol

>student []array = new student[x]; This creates an array of references to student objects. It doesn't create the actual student objects. You need to do that as well in your loop: [code=csharp] student[] array = new student[x]; for ( int i = 0; i < array.length; i++ ) { array[i] …

Member Avatar for Prince Adusei-O
0
140
Member Avatar for cppgangster

[QUOTE]are these not any more part of standart?[/QUOTE] That's correct. Those are library extensions provided by some compilers.

Member Avatar for abhimanipal
0
128

The End.