6,741 Posted Topics
Re: [QUOTE]I wants to know the code ??[/QUOTE] No. Read [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]the rules[/URL]. | |
Re: [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 … | |
Re: [QUOTE]It is a back-end web platform solution for a specific industry.[/QUOTE] That's such a helpful description. :icon_rolleyes: | |
Re: [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] … | |
Re: [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 … | |
Re: Please point out the line that should be displaying the contents of the file. | |
Re: [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 … | |
Re: You neglected to mention the problems. | |
Re: 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 … | |
![]() | Re: [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 … ![]() |
Re: 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: … | |
Re: [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. … | |
Re: Who wants to bet that region is 0 for one of the setVotes() calls? :) | |
Re: 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. | |
Re: Default function template arguments have been added to C++0x, yes. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: >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. | |
Re: 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 … | |
Re: 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. | |
Re: [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 … | |
Re: 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. | |
Re: Might I suggest looking at the assembly output for your code? You might be enlightened as to what the code generator is doing. :) | |
Re: 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. | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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(); … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: [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] | |
Re: [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 … | |
Re: [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 … | |
| |
Re: [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 … | |
Re: 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]. | |
Re: [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! :) | |
Re: 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] … | |
Re: 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. | |
Re: 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 … | |
Re: 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. | |
Re: >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] … | |
Re: [QUOTE]are these not any more part of standart?[/QUOTE] That's correct. Those are library extensions provided by some compilers. |
The End.