6,741 Posted Topics
Re: [B]>How can I resolve this issue??[/B] If you have control over the source for either library, simply change the name. If you don't have control, that's what I'd call a namespace nightmare. ;) One way to work around it is by using a wrapper library. The purpose of a wrapper … | |
![]() | Re: >in c++? is the syntax the same or different? [code] #include <iostream> #include <string> using namespace std int main() { string name = "Derrick"; string filename = name + ".txt"; ofstream file ( filename.c_str() ); if ( file ) { file<< name <<endl; } } [/code] |
Re: [url]http://www.comeaucomputing.com/tryitout/[/url] Configure it to compile C89/90 or C99 and fix the errors. That should take you a [i]long[/i] way toward having pure C code. | |
Re: [B]>Ive been googling everywhere, but havent really >found any examples on how to properly use it.[/B] I suspect what you found is what most of us would tell you: [code] for (string::size_type i = 0; i < s.size(); i++) s[i] = std::toupper((unsigned char)s[i]); [/code] You'll probably also find the broken: … | |
Re: [B]>how can this be taken care of? [/B] You have no choice but to allocate a new block of memory. Since str is a local array but needs a longer lifetime, you can replace it with dynamic memory: [code] char* foo (int ch) { char* str = malloc(10); if (!foo1(str, … | |
Re: Are you sure that the literal character is using ASCII? [code] #include <iostream> #include <string> int main() { char a = 'รก'; char b = char(160); std::cout<< a <<" == "<< std::char_traits<char>().to_int_type(a) <<'\n'; std::cout<< b <<" == "<< std::char_traits<char>().to_int_type(b) <<'\n'; } [/code] My guess is that your text editor is … | |
Re: Just because it compiles without errors doesn't mean the code works. Your I_simpson function is hanging, which means it doesn't return, which means you don't get any output. | |
Re: >"don't ever use scanf() in the real world" ... Without any error checking. | |
Re: [QUOTE=vegaseat]Writing windows programs in C/C++ can be a bear for even experienced programmers. I started out with the DEV C++ package and quickly switched to BCX. This is a basic to C/C++ translator that uses simple basic code and allows inline asm and C code. If you are familiar with … | |
Re: [B]>what are the advantages of a dummy head linked list and what is the implementation steps?[/B] [URL="http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_linklist.aspx"]Click Me[/URL] [B]>how many linked list are there around[/B] Probably more than you can count, it's a very common data structure. | |
Re: [B]>This is the first time I've ever seen this and I'm interested in any >reasoning why we shouldn't just remove it to eliminate code bloat.[/B] I can't claim to know what the original author was thinking, but I'm a fan of the double inversion for forcing an integer into a … | |
Re: [B]>If anyone can help with this.. I'd appreciate it![/B] This is a very simple algorithm that requires little more than common sense. Just pretend someone is handing you money and that you get to keep the smallest and largest bills. When you're done outlining the steps, turn the process into … | |
Re: I'd say the error is a failure to pay attention. You use a different name for the index_of_next_smallest function when calling it, and neglected to declare indexPtr everywhere it's used | |
Re: This is just an extension of the largest value program. A super easy way to do it is two loops in succession. The first loop finds the largest value unconditionally, then the second loop finds the largest value excluding the result of the first loop: [code] max = first while … | |
Re: [B]>How would I make all letters be an invalid input?[/B] I notice you don't check the return value of scanf. That's the first step in recognizing whether it failed or not. Then you can recover: [code] while (scanf("%f", &purchase) != 1) { /* This is me being lazy */ while … | |
Re: [B]>Will pay money for doing the assignment.[/B] No, cheater. Piss off. [B]>can u give me the codes...[/B] No, cheater. Piss off. | |
Re: [B]>while (listPtr -> next != NULL) delete listPtr;[/B] Unless listPtr->next is NULL on the first iteration, you're deleting the same pointer multiple times. Try something more like this for the whole destructor: [code] while (listPtr != NULL) { NodePtr save = listPtr->next; delete listPtr; listPtr = save; } [/code] | |
Re: Put it in the list of startup applications on installation. | |
Re: Grab a draft of the C++ standard (google is your friend) and search for "Temporary objects". | |
Re: Do you keep track of who up or down votes, or is it a simple counter? | |
Re: [B]>This website is complete with text and video tutorials made by my friend and I.[/B] As baby steps tutorials go, it's not the worst I've seen. However, from reading the tutorials, you don't strike me as being at a level where you should be teaching without a chaperone. | |
Consider the following program and input file: [code] #include <algorithm> #include <cstdlib> #include <ctime> #include <functional> #include <fstream> #include <iostream> #include <iterator> #include <string> #include <vector> #include "natural_compare.h" struct natural_less: std::binary_function<std::string, std::string, bool> { bool operator()(const std::string& a, const std::string& b) { return natural_compare(a, b) < 0; } }; std::vector<std::string> … | |
Re: If you bothered to read the last week or so of posts then you would have seen that I gave a complete implementation for something like this. You could easily modify that or use it as a basis for your own implementation. But no, you wanted someone to do your … | |
Re: It's not the namespace, it's the stuff in the namespace that gets redefined. Ideally you would put only declarations in a header and definitions in a separate implementation file. But you can help alleviate the problem with [URL="http://en.wikipedia.org/wiki/Include_guard"]inclusion guards[/URL]. | |
Re: argc is there for a reason, use it to determine if argv[1] even exists. | |
Re: Works for me: [code] #include <stdio.h> #include <time.h> int main(void) { time_t t = time(NULL); struct tm *now = localtime(&t); printf("Day of the year: %d\n", now->tm_yday); return 0; } [/code] Output (for Feb 15th, 2010, EST): [code] Day of the year: 45 [/code] What was your "incorrect number"? | |
Re: [B]>else if (weight >= 100 & < 200)[/B] "else if weight is greater than or equal to 100 and less than 200". That makes perfect sense, but it's wrong. C++ won't infer that in the second half of the expression you're still trying to compare with weight. Further, & is … | |
Re: [B]>ans is -2201 how? >please explain the ans >please explain[/B] Why don't you start a new thread instead of hijacking an old one, then try to explain it yourself and we'll make corrections. We're not here to do your homework. p.s. Bumping the thread with the same question after a … | |
Re: Why don't you just tell us your teacher's email address so that we can send the program directly? | |
Re: Sounds like homework questions. How about you come up with at least one reasonable answer to each and we'll tell you if they make sense and possibly offer more. | |
Regular: A Daniweb member who visits/posts frequently, and tends to be friends with others who visit/post frequently. New members could easily be overwhelmed by the mass of people running around, and it's hard to fit yourself in a community as old as Daniweb, where members are already well entrenched and … | |
Re: Did you implement those functions or just declare them? | |
Re: 1) No, the lifetime of a string literal is equal to that of the program. 2) Yes, the address you're saving is still that of the string literal. 3) You're pointing to a string literal, so it's all good. However, note that identical string literals may share memory, so you … | |
Re: [B]>There are a lot of programs that do not require GUI, console, or human interaction.[/B] Sadly, there's a misconception (especially among beginners) that GUI programming is the "next step" toward being a real programmer. :icon_rolleyes: | |
Re: [B]>Why the output is 100?[/B] var + 12 = var12. [ICODE]printf("%d", var12)[/ICODE] prints the value of var12, and var12 was initialized to 100. | |
Re: [B]>Try it like this[/B] The size of the first dimension of an array parameter isn't required, but you can put it there and it'll be ignored. The two lines of code you posted are functionally identical. | |
Re: [B]>How can i do this??[/B] Did you start by searching? Converting an integer to a string is a very common question. | |
Re: [B]>fgets(usercheck,256,stdin);[/B] Don't forget to check for failure. The last thing you want to do is dereference a null pointer on the next line. [B]>usercheck[strlen(usercheck) - 1] = '\0';[/B] While this covers the average case, it's possible for fgets to succeed yet not end with a newline. Unless you want an … | |
Re: We can read you know. You don't have to capitalize the "important" words for us. :icon_rolleyes: | |
Re: [B]>(1) "(when we insert one character)Why code prints "10" >after printing ascii value of the character we insert?" [/B] Because you actually typed two characters? You press the 'a' key right? Then you press then [Enter] key, right? That's two characters: 'a' and newline. I'd love to hear why you … | |
Re: [B]>There are no known sorting algorithms that perform in linear time.[/B] There are no known [I]comparison-based[/I] sorting algorithms because the limit with a comparison tree is Omega(nlogn). But linear algorithms do exist using other methods, such as distribution. | |
Re: [B]>Am I right? wrong? missing something?[/B] That's a toughie. While a compiler [i]might[/i] inline your function, it's best to assume that there will be overhead. However, the overhead of a function call isn't exactly significant these days, which is why it's generally better to modularize (your teacher's suggestion) than to … | |
Re: [B]>If you shift more than 31-bits left[/B] The behavior is undefined. [B]>The issue is the fact that 32-64=-32 which on a right shift operation is 32-bits left.[/B] No, that's undefined too. If you shift in either direction by a negative value or by a value greater than or equal to … | |
Re: [QUOTE=gerard4143;1128999]I know this is knit picking... [QUOTE]We all know that we can use the name of an array as the pointer to that array,[/QUOTE] The name of an array is a label which is a convenient human readable memory address. Its not a pointer...[/QUOTE] Actually, the statement you quoted is … | |
Re: I can think of two super easy ways to do it: [LIST=1] [*]Use a second array and copy the parts that aren't deleted. All you need to do is find the start of the substring you want to delete and it's a matter of calling strcpy. [*]Shift all contents of … | |
Re: [B]>zangetsuu[/B] I can't decide if you like Bleach but only watched the English dub, or zangetsu was taken and you just added an extra 'u' to the end. If it's the former, the name Zangetsu is pronounced something like "[I]Zahn[/I]gets". The "oo" sound at the end is virtually silent when … | |
Re: [B]>This is a little hard for me to believe.[/B] It really depends on the job. I've done interviews in other fields where that's a fairly accurate statement, assuming "can't write code at all" is stated more along the lines of "can't do much beyond 'hello world'". We can blame the … | |
Re: [B]>This is my 1st time hearing about SRC Code and my teacher isnt being a big help.[/B] Presumably you learned about SRC assembly in class, otherwise your teacher wouldn't give the assignment. The link doesn't work, so I can't see your assignment. Perhaps if you gave some more details on … |
The End.