3,183 Posted Topics
Re: I'm willing to bet that you didn't think the Enter key counts as a character in the stream. Your second scanf() reads the newline from pressing the Enter key, so you're replacing whatever is typed for `b` with `'\n'`. Unless you type multiple characters for `b`, of course. | |
Re: scanf()'s %s specifier doesn't read whitespace, that's the delimiter. Since you learned not to use gets(), the proper replacement is fgets(), not scanf(). | |
![]() | Re: This: const hello ptr1, ptr2; Is equivalent to this: const char *ptr1, *ptr2; And this: const char *ptr1; const char *ptr2; And as we already know, it's the *pointed to* value that's const in these cases, not the pointer. To make the pointer const, and thus unable to point to … |
![]() | Re: `const` doesn't mean that the object is stored in read-only memory, though that's a possibility. All `const` means is that the compiler will enforce read-only uses of the variable. So you can attempt to subvert the type system by casting away `const` and it'll probably work, but there's no guarantee. ![]() |
![]() | Re: Barring truly hideous solutions like setjmp and longjmp, or terminating the program entirely with exit() or abort(), you really have no choice but to roll back up the recursive chain. This is one of the down sides of recursion, especially when dealing with things like ad hoc traversal over a … ![]() |
![]() | Re: The address produced by using `arr` in value context is then reinterpreted as a pointer to int, which can then be dereferenced to get the value stored at `arr[0][0][0]`. This particular cast is safe, at least until you decide to iterate over all of the items: int arr[2][2][2] = {1, … ![]() |
Re: Please provide evidence of having done some work yourself if posting questions from school or work assignments. | |
Re: There are many libraries you can (and should!) use. Cryptography is exceptionally easy to get wrong, where the result appears to work but is easily cracked. [OpenSSL](http://openssl.org/) is one popular library. | |
Re: > A pity that the bump action does not get reset.... We considered updating those particular fields upon deleting the last post of a thread, but at the time decided it was too expensive. | |
Re: The Windows API defines a macro called ERROR, which is replacing your use of ERROR with whatever value is defined. It does the same thing with TRUE and FALSE, which is why in the past I was forced to do annoying things like this: enum boolean { B_FALSE, B_TRUE }; … | |
Re: Post an example program, please. | |
Re: > str[j]=str[i]; That's not meaningful, but it's probably a typo where you clearly meant the right hand side to reference str1. However, that's evidence that very similar names are easy to mix up and result in subtle bugs. You also neglect to terminate the destination string with a null character. … | |
Re: And before anyone chimes in with swaps using XOR or arithmetic operators that they think are clever: your solution is bad, and you should feel bad. | |
![]() | Re: When you say `*p++`, what really happens is `*(p++)`. So you're evaluating to the value pointed to by `p`, and then incrementing the address stored in `p`. So let's break it down: y = &x; The address stored in y is 500 (going off your original stated assumption for simplicity). … ![]() |
Re: With only the given information, I'd favor breaking down the row and building a table in C# rather than trying to transform the rows in the query. It looks like all you're doing is splitting each row into two rows with the first id duplicated and assigning either the 2nd … | |
Re: > char *copy = NULL,addressholder2; copy = &addressholder2; *copy = *string; //string is the result of the html form copy[1] = '\0'; strcat(copy,"test"); //HERE IS THE CODE THAT WORKS This is terrifying. So you have a pointer to a *single character*, and then immediately start writing *beyond* that single character … | |
Re: Put simply, if the application isn't intuitive, people won't use it unless they're forced to do so. If they need to refer to a manual, the application isn't intuitive. If they need to go to a class, the application isn't intuitive. In your shoes, my first line of attack would … | |
Re: Your tree generation algorithm isn't really doing anything because the nodes aren't linked together. Compare and contrast: #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char *token; struct node *left; struct node *right; }; struct node *make_node(const char *token, struct node *left, struct node *right) { struct … | |
Re: > ancient dragon will you please tell me that what is that problem of '\n' with fgets. i am not getting it from your answer. will you please explain it more . isn't scanf appends '\n' to the end ? please clearify me. Try it and see. You can't always … | |
![]() | Re: > my question is that how can we use "main" (only name without parenthesis) as the pointer to a function ? because > main() is a function. I am not getting it how is it true ? It's syntactic convenience based on the fact that you can only do two … |
Re: > What happens if I removed the "using" word? Will it affect my program? It would fail to compile... | |
Re: In the first, the global array is likely to be stored in the BSS (uninitialized data) segment of the executable file itself while the local array is more likely to be drawn from the stack at runtime. Because stack space is already allocated to the executable in one way or … | |
Re: > The difference between using refrences(&var), and pointers(*var) is that using refrences is more efficent because you do not have to derefernce the object. While there's potential for such an optimization, I wouldn't rely on it. The benefit of references is largely syntactic convenience (for more than you probably expect). … | |
Re: That's by design. Unverified and newbie members aren't allowed to create new tags, only use existing ones. You probably crossed the threshold between a newbie member and a community member (these are our terms for the permissions levels) in those three hours. By the way, the criteria for promotion from … | |
Re: > So whats is C equivalent of a C++ string? There isn't one. You could go out and find a third party string library like [bstring](http://bstring.sourceforge.net/), but unlike std::string, you don't have the option of a standard string "class" in C. | |
Re: > printf ("The value is %d and the address is %p\n", x, & x); Another minor point, but to be strictly correct you must to cast the argument for %p to void\* because that's the type printf() expects: printf("The value is %d and the address is %p\n", x, (void*)&x); | |
Re: [How to ask questions the smart way](http://www.catb.org/~esr/faqs/smart-questions.html). | |
Re: In your second loop you have this: intConcatenatedStringIndex = (intLengthOfSource + 1) That's wrong, and it introduces an off-by-one error by setting intConcatenatedStringIndex one element too far. You'll have better results (and not an invervening garbage character) by initializing the index to intLengthOfSource without any changes. On a side note, … | |
Re: > How can I know my logic skills are good enough for programming? Can you methodically work toward an understanding of a problem and devise a solution using common sense? If so, your logic skills are good enough. > Is it something you either have or you don’t; or do … | |
Re: > What are the for/against's for such implementation on the site? Assuming database related or the content that the less mature individuals would put in the signatures. Signatures are limited in size so that they aren't obtrusive and take away from the thread. I've been on a few forums where … | |
Re: > I found this unique program which will allow the user to create his own format specifier which will use "%b" as format specifier to convert a integer directly into binary. Hardly unique, it's just another naive implementation of printf() that adds specifiers at the author's whim. Not that it … | |
Re: > read that every class extends a object class by default. Yes. > then it should cause multiple inheritence and must not be supported by Java. Think of it like this: when you explicitly extend a class, Object isn't involved except as a base of the class being extended. When … | |
Re: Please post a complete program along with starting values for the variables. I'd make an educated guess that you're dividing by zero, but that's pure speculation given your lack of detail. | |
Re: I hate to be "that guy", but if you made it this far and still can't produce even a vague idea given the entire field of computer engineering, you probably don't deserve to graduate. | |
Re: > Couldn't find installable ISAM. Have you read [this knowledgebase article](http://support.microsoft.com/default.aspx?scid=kb;en-us;90111) and tried the resolution steps? Also, are you sure your connection string is correct? | |
Re: > i keep getting errors after adding fgets. Nobody can help if you don't post your code or tell us what the errors are. > i have no idea how to put the storage properly since the number at start is the line number and the operation in the line … | |
Re: Your paraphrasing of the output is incorrect, and that hides a critical piece of information in figuring out what's wrong. Specifically "Book Number : A100" would not be part of the output. The output for A200 would actually be: Enter ISBN : A200 Book Number : The_Book_of_life Book Title : … | |
Re: Assuming you mean a C++ keyword, the list is short. Just store all of them in an array and do a lookup comparison. | |
Re: There are a number of ways to do it depending on your efficiency needs. Usually a priority queue is optimized for maximum retrieval speed of the highest priority item. So you would do a sorted insert of new items according to the priority relation: template <typename T> void PQueue<T>::Insert(T item) … | |
![]() | Re: > hi, can anyone please explain why i am getting output as "ishq" even if i=0.3 so if condition must be false. pleas help i am not getting it. [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) |
Re: > name_.first(firstName), name_.second(lastName) C++ doesn't support initializing individual members of a member object in the initializer list. Ideally you'd want to add a constructor to the Name class that takes a first and last name, then write the initalizer list like this: explicit Student(const std::string& id, const std::string& firstName, const … | |
Re: > I need a code which can solve the equations like this :- > 56*78+(78/8) Nobody is going to just give you the code. To do it properly would involve writing essentially a tiny compiler for mathematical expressions where you tokenize the line, convert it into an expression tree, and … | |
![]() | Re: For what purpose would you want a constant union? Anyway, you *can* initialize a union to the first listed member prior to C99, and you can use a designated initializer for an arbitrary member in C99 and later. /* Earlier than C99 */ const union emp e1 = { "doodage" … ![]() |
![]() | Re: > And i want to ask that in p[] definition, why it is written (int) with every element since a is already an pointer. It's already a pointer, but the type is different. Try removing the cast and you'll get an error similar to: "*type mismatch between int(\*)[2] and int\**" … ![]() |
Re: The #define directive is a glorified cut and paste. You can see why that macro is wrong by doing the cut and paste manually: if(a=='A','B','C','D','E','F','0','1','2','3','4','5','6','7','8','9') printf("hexadecimal"); Well, you may not see it because this is a common confusion point for beginners to C. You don't compare a variable to a … | |
Re: > but here i require to allocate memory to b. why is so? Where did you think the memory would come from? Pointers don't magically point to infinite memory on declaration, you have to point them to a block of memory that's allocated for that purpose, either through dynamic allocation … | |
Re: > Make an array with every exercise and randomly pick one? Yup. Though for a workout generator you probably don't want to pick the same exercise twice, so a random shuffle may be more appropriate. > How would I go about doing that? Here's an example: #include <stdio.h> #include <stdlib.h> … | |
![]() | Re: > I already learnt linked list, trees and all. Clearly you haven't realized how many variations of the above there are. Do you know intimately all of the tree variations listed [here](http://eternallyconfuzzled.com/jsw_home.aspx)? That's just a teeny tiny helping of tree variations and enough to take up a few months of … ![]() |
Re: What's the problem? Barring a minor semantic error (failure to return something from menu()) the program seems to work properly with a few simple test numbers. |
The End.