6,741 Posted Topics
Re: So much time wasted for such a simple task. I wonder if the OP really wants to do it and isn't just looking for a handout. | |
Re: It looks like you get the concept just fine. The only problems in your code are syntax related (and the poor practice of using conio.h). Fixing those errors produces working code: [code] #include<stdio.h> int main() { int counter,howmuch; printf("How many numbers do u want to print"); scanf("%d",&howmuch); counter=0; while (counter<=howmuch) … | |
Re: That's an interesting test, but somewhat unrealistic since the words are random. I found myself slowing down significantly (74 WPM) because I trip up when copying poorly constructed grammar. | |
| |
Re: You're redirecting stdin to the pipe, it won't read from the keyboard anymore. If you want to manage both piped data [i]and[/i] keyboard data, a better approach is opening the pipe within your program rather than redirecting input from the command line. For example: [code] #include <stdio.h> #include <string.h> #include … | |
Re: Most of the fast string searching algorithms can be applied to non-string arrays as well. | |
Re: How are those words stored? Do you know about srand() and rand()? Are you just selecting a single word, or do they need to be randomly ordered? I'd start by storing the words in an array and then using rand() to get a random index into the array. This design … | |
Re: [QUOTE]No it is not a Class Assignment ![/QUOTE] That's irrelevant at this point. We're cracking down on "begging" questions, so in the future you may find similar threads to this one deleted. By "begging" we mean questions that fail to show proof of effort such as described [url=http://catb.org/~esr/faqs/smart-questions.html#before]here[/url]. | |
Re: We're not a homework writing service. Please provide proof that you've made an honest attempt to solve the problem on your own. | |
Re: Why 50? Changing a user's name is quick and easy, provided the new name is available, so I don't see a problem with allowing it regardless of post count. Otherwise those with less than 50 posts would probably create a new account and take up both names, which just clutters … | |
Re: [QUOTE]That's like saying if you can nail two pieces of wood together and they don't fall apart then you are a carpenter.[/QUOTE] Your analogy neglects the "and are used" part. [QUOTE]I would have preferred to the the statement amended as[/QUOTE] I notice that you didn't change the offending statement that … | |
Re: [QUOTE]According to me,[/QUOTE] This is an odd phrase. Just saying. [QUOTE]this code should produce indefinite result because of no specified null character at the end of the string[/QUOTE] Correct. [QUOTE]Why is the null character present in the 13th memory location EACH TIME?[/QUOTE] In practice, it depends on how your compiler … | |
Re: [QUOTE=mike_2000_17;1617747]Or maybe something along the lines of: [CODE] #include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream infile("input.txt"); ofstream outfile("output.txt"); int value; while(infile >> value) { char mod_val = (--value) % 52; outfile << string(value / 52 + 1, (mod_val < 26 ? mod_val + 'a' … ![]() | |
Re: Enumerations constants are symbolic constants representing integral values. If you want the string representation of the symbol, you must create it manually: [code] #include<stdio.h> int main(void) { enum days { one, two, three, four, five, six, seven, eight, nine, ten }; const char *days_str[] = { "one", "two", "three", "four", … | |
Re: >while (true) { You don't break from this loop anywhere. It's going to continue looping forever, after a short time getline will start to fail and you'll get the output you posted. Try this instead: [code] while ( getline ( cin, input ) ) cout << input << endl; [/code] … | |
Re: [QUOTE]what is output[/QUOTE] Unpredictable in all cases. [QUOTE]plz explain it..[/QUOTE] The expression [ICODE]a + !a + ~a + ++a[/ICODE] invokes undefined behavior by using the value of [ICODE]a[/ICODE] in a way that doesn't assist in computing the new value. It falls under the sequence point rule of an object being … | |
Re: Your question is confusing, but the "limit" is based on the value of y, not the count of fibonacci numbers you've printed. Perhaps you wanted the latter? ![]() | |
Re: What does your book say? Did you search google? Have you made [i]any[/i] attempt to answer this trivial question on your own? ![]() | |
Re: You might be able to get Visual C++ 2005 Express somewhere, but I don't believe Microsoft directly offers it anymore (they're up to 2010), so there's some risk involved. If you're asking for one of the non-express versions of Visual Studio, that's illegal. | |
Re: [QUOTE]Line 23 will short-circuit if ptr is NULL and hence the CantGetHere() function won't be called, right?[/QUOTE] Correct. [QUOTE]Just want to confirm that ||, like &&, always works from left to right.[/QUOTE] Yes. Both are short circuited and have left to right associativity. | |
Re: It could be your IRC client. I've been logged in all morning with no issues. | |
Re: [QUOTE]Nathan memory is contious and it will always be for vectors, deques.[/QUOTE] For vectors, yes. For deques, there's no requirement that memory be contiguous. | |
Re: Are you setting an environment variable, or creating a symbol definition? Those are two completely separate things. Can you show an example of the make file? | |
Re: [QUOTE]How does this give 3, shouldnt it give 3*sizeof(int) cuz its an integer array.[/QUOTE] But it's not an int array, it's a char array. | |
Re: The size of a character depends on the encoding for your character set. Do some research on ASCII and Unicode for details. | |
Re: If you have a matrix in row major order, you can simply swap the indices to use column major order: [code] #include <iomanip> #include <iostream> using namespace std; int main() { const int n = 4; int mat[4][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, … | |
Re: [URL="http://cboard.cprogramming.com/c-programming/88495-development-process.html"]Clicky[/URL]. | |
Re: [QUOTE]I thought it was just getting the address of the first element of the array.[/QUOTE] That's exactly what it's doing. However, that address is being interpreted by scanf() as the starting address of a string. To print the address itself, use [ICODE]%p[/ICODE] and cast to [ICODE]void*[/ICODE]: [code] printf("%c %p %s\n", … | |
Re: [QUOTE]and so, entry[i].interface = strtok (NULL, "\t"); returns 4th (i.e., last) token of (i+1)th line.[/QUOTE] All of the [ICODE]entry[i].interface[/ICODE] pointers point to [ICODE]buffer[/ICODE]. On each iteration of the loop, you change the contents of [ICODE]buffer[/ICODE]. Do you see the problem now? | |
Re: [QUOTE]codes always have to be OOP[/QUOTE] OOP for the sake of OOP, eh? Your teacher sounds like an idiot. [QUOTE]i have 3 but cant seem to find away to take one out.[/QUOTE] The easiest way would be combining the two from your inner loop with the conditional operator: [code] #include … | |
Re: [QUOTE]argc is the counter of how many arguments that are passed in to the program (it is 1 with no additional arguments passed because it passes it's own path by default)[/QUOTE] argc is allowed to be zero. Further, even if argc is greater than zero, [ICODE]argv[0][/ICODE] is not required to … | |
Re: Here's an idea: write your own code from scratch instead of being a helpless baby. You'll learn a lot more than you would by cheating your way to a solution. Besides, those instructions are just a few steps shy of being a line for line description of the program. Do … | |
Re: [url]http://www.yui-net.com/[/url] My favorite is definitely "Good-Bye Days" from that album. | |
Re: [QUOTE=erigib89;1614435]What happens if this was a muti-threaded program?[/QUOTE] The same thing that happens when you have a single resource (the file in this case) and multiple threads trying to access it simultaneously. Concurrency safeguards would need to be added to the code. | |
Re: [QUOTE]1. How do you guys pass char and string to a function (the correct way)?[/QUOTE] There's not really anything wrong with how you did it. [QUOTE]2. Is my code for counting a letter in a string the best way?[/QUOTE] I would only have minor nitpicks. The algorithm is sound. | |
Re: C and C++ are different languages. You don't need to learn any part of C before starting with C++. /thread | |
Re: You want a compiler/IDE something that doesn't need to be installed on the host machine. Obviously that excludes Visual Studio. ;) IIRC, [URL="http://www.digitalmars.com/"]Digital Mars[/URL] is like that. If it's already built, MinGW can be "installed" simply by copying the files (I'd recommend the [URL="http://nuwen.net/mingw.html"]nuwen build[/URL]), and for an IDE Code::Blocks … | |
Re: [QUOTE]I am studying C# at University but feel I may be rather restricted as to what I can do later on.[/QUOTE] Interesting. I haven't felt restricted with C#, and that's coming [i]from[/i] a C and C++ background. Though a lot of people associate C# with .NET rather than the internationally … | |
Re: [QUOTE]This concept is fairly simple and I would assume that there is a good way to go about doing this.[/QUOTE] Assuming polymorphism doesn't work for some reason (usually due to violation of the substitution principle) then dynamic_cast can be used to discover the type. However, if you find yourself using … | |
Re: Your user array can only hold a single character. Since a string ends with '\0', that means it's always going to be empty. Further, using %s in scanf() without a field width means you're not respecting the lack of available space on the array. I'm totally unsurprised that the snippet … | |
Re: Your request lacks sufficient information, and it reeks of "please do it for me!". I suggest you read our rules, then how to ask a [URL="http://www.catb.org/~esr/faqs/smart-questions.html"]smart question[/URL]. | |
Re: The problem is extraneous characters in the stream, but you might consider using scanf() to do the heavy lifting of reading only digits: [code] #include <stdio.h> int main(void) { char year[5]; int n; fputs("Enter year introduced: ", stdout); fflush(stdout); while (scanf("%4[0123456789]%n", year, &n) != 1 || n != 4) { … | |
Re: [QUOTE]On the one hand, happygeek seems to think it's all about the quality.[/QUOTE] That's the ideal, yes. I'm open to ideas for [I]making[/I] people post quality content. [QUOTE]But when it comes to doing something about it, the enthusiasm seems to be more muted[/QUOTE] The problem is maintaining quality without being … | |
Re: I have no problem writing some examples for the wiki. As for the tutorial(s), if we're targeting beginners then a holistic approach might be better. Instead of just focusing on new features in isolation, it would be a complete beginner's tutorial on C++, but from the perspective of the new … | |
Re: [QUOTE=pseudorandom21;1607660]I need to know a bit about this "default int" thing in C. What I mean is, is this actually ok and with what version of C is it ok? [code] main() { return 0; } [/code] As far as I knew this was standard modern C (i.e., no retarded … |
The End.