6,741 Posted Topics
Re: You can traverse a two-dimensional array with a nested loop: [code] for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 10; j++ ) printf ( "%c ", array[i][j] ); } [/code] >Second, that how would i put character 'A' in location … | |
Re: >I'm having some trouble understanding the advantages >and disadvantages of using scanf over fgets. I imagine because the comparison is difficult. scanf and fgets do different things. scanf is designed for formatted input and fgets is designed for unformatted input. >But in what way does fgets prevent that from happening? … | |
Re: >bt i dont hv >using namespace std; >at d beginning... If you're not using namespaces or getting compilation errors then you're not learning standard C++. I'd wager your teacher is teaching you C++ on his favorite compiler, which happens to be old as dirt. >at d beginning...i olwayz write progam … | |
Re: You already have a counter, so just print that value instead of something hard coded: [code] cout << "Person #" << i + 1 << ": "; [/code] | |
Re: >What am I doing wrong? twomers already showed you. 1,2,3,4 isn't a list of values, it's four expressions separated by the comma operator. The result is most certainly not what you expected. Here's what actually happens: PeopleTypes[i] != 1 is tested. If PeopleTypes[i] is actually 1, the expression is false, … | |
Re: Your code is riddled with syntax errors. So many, in fact, that it's not even worth my time to point them out for you. I recommend you scrap your code and start over, but this time, pay close attention to what you're doing (programming requires an eye for detail) and … | |
Re: >I read up on switches, and it says they're used for strings, not chars Quite the contrary. A switch doesn't work with strings, but because char is an integral type, it works just fine as a switch case. | |
Re: >Can anyone recommend a good IDE to get started with, and how I can set up. Visual C++ Express is good, and it's easy to install. Dev-C++ is also good and easy to work with, but it's kind of a dead project. I've been hearing good things about Code::Blocks, but … | |
Re: >if ((pos%(random+5))==0) Dare I ask where you got the 5 from? | |
Re: >I would like to display the highest randomly generated number in the equation. How is that trickier? Keep a running maximum (like the sum in your average algorithm) as you walk through the array. When you see a value that's larger than the maximum, it becomes the new maximum: [code] … | |
Re: >is it possible to input unlimited amount of nummbers nut just number 1 + number 2? Yes. You need a running sum, a count of how many numbers there are, and one variable for the number. Then you'd do this: [code] int count = 0; int sum = 0; int … | |
Re: Add them to a sum using a loop, then divide by 30. That's generally how one would find the average of a list of numbers: [code] double sum = 0; for ( int i = 0; i < 30; i++ ) sum += a[i]; cout<<"Average: "<< sum / 30 <<'\n'; … | |
Re: >Is this encoding designed to hide the programming? Compiled programs aren't like HTML. The source code is lost during compilation unless the executable format supports metadata that can reconstruct it, like .NET. Those symbols you saw were the text editor's attempt to turn binary into printable characters. >How can I … | |
Re: >//Yes I did put in 'return 0' because it's bad >//practice to leave it out and yada yada yada... You're not getting away with this one. :) Explain why it's a bad practice, please. | |
Re: Your declaration is off. It declares pointer_to_array_of_atype to be an array of pointers to aType, not a pointer to an array. To get a pointer to an array, you wrap the asterisk and identifier in parens. But also keep in mind that the array sizes should match: [code] aType (*pointer_to_array_of_atype)[5]; … | |
Re: >I'm having some problems with creating user defined functions. A function definition has four parts: the return type, the function name, the parameter list, and the body. It looks like this: [code] <return type> <function name> ( <parameter list> ) { <body> } [/code] This declares and defines a function. … | |
Re: Wow. Scary. The first two errors you're getting come from the fact that you can't use a variable if you haven't declared it first. num_rows and num_colms don't exist in main. The next error is because your syntax is completely screwed up. None of the braces match, there are extra … | |
Re: >Am I wrong? Yes, they're different in pretty much every way due to the differing syntax and semantics of scalars and arrays. You can't even say that they have the same storage costs because arrays are allowed to use extra space before and after the accessible items. | |
Re: >if ( i >= 'LetterToMatch') I'm going to go out on a limb and guess that you meant: [code] if ( i == LetterToMatch ) [/code] LetterToMatch is a variable, and you're checking to see if i matches it, correct? Also, if you're going to test against LetterToMatch, you need … | |
Re: It sounds like you aren't actually linking with the library when you build your program. Why don't you describe exactly how you're compiling and linking the program? Oh, also mention your OS and compiler. | |
Re: >void transpo_sort(int a[], int i); This doesn't call the transpo_sort function, it declares the transpo_sort function. In other words, absolutely nothing is happening to your array. >printf("After Pass #2:%7d,%5d,%5d,%5d,%5d,%5d,%5d,%5d \n", a[i],a[i],a[i],a[i],a[i],a[i],a[i],a[i]); i is 0, and a[0] is 7. It's no surprise that printing a[i] eight times gives you eight 7's. | |
Re: >What about if someone wanted to add something to the beginning or somewhere between? It's more or less the same deal. You move everything from the index you want to add to, to the end of the array forward by one element. Then you add the new value to the … | |
Re: You can use the %n conversion specifier to find out how many characters were read and adjust the source string accordingly: [code] #include <stdio.h> int main( void ) { const char *src = "this is a test"; char word[5]; int n; while ( sscanf ( src, "%4s%n", word, &n ) … | |
Re: >Here's the solution: Great. Now the OP has learned absolutely nothing from this exercise. I hope you end up working with someone who breezed through school without having to learn, because then you'll realize why giving away the entire solution like that hurts more than it could possibly help. | |
Re: >I would avoid of load the whole file in memory and then printing it line-by-line.. Read a line, process it, and write it to a temporary file. Then delete the original file and rename the temporary. >is it possible ?? It's hard to say. You talk about appending to a … | |
Re: >how about this form. You're not even reading AD's posts, are you? | |
Re: >what might be the problem? My guess is PEBKAC. | |
Re: >i need help here(urgent!!) First thing's first, urgent for you doesn't mean urgent for us. Deal with it. >gets (string); Don't ever use gets. It's evil, and there's no way to make it less evil. Use fgets instead. Your count isn't counting the right thing. You're counting the number of … | |
Re: >I've completed programs with the use of the getline function and it works ok. I bet those programs didn't try to pass a double into getline instead of a string: [code] double number;//the grades as in the infile while (getline(infile,[COLOR="Red"]number[/COLOR],'\n') [/code] There are other problems too: >int num;//number of grades … | |
Re: Nobody will write it for you. If you're not willing to do it yourself, we're not even willing to help you a little bit. | |
Re: >I got it to do a factorial number , now it want to display the results in a pyramid Do you understand how to use factorials to derive an individual number from the pyramid? | |
Re: >can someone tell me if the code is right. No, it's not right. >#include<conio.h> I can't stand programs that abuse conio.h. You don't need it, so why use it? >int num1,num2,num3; >int num4,num5; There's exactly zero reason for using global variables. >printf("ENTER NUMBER"); Unless you print a newline after the … | |
Re: Those errors have more to do with not knowing how to use a class than not understanding trees. Because those functions are member functions, you need an object of the tree class before you can call them. | |
Re: >for(int i=0; i<10; i++) /* Not proper C syntax */ Not proper C89 syntax. C99 supports this feature. | |
Re: >Most of it is done Not really. What you want to do is actually pretty involved if you want to do it right. If you want to keep it relatively simple, make the functions that work with a wordInfo object into member functions. Then from the definition of those functions, … | |
Re: fseek64 isn't a standard function, so if it exists for your compiler, the documentation will tell you where to find it and how to use it. Have you tried fgetpos and fsetpos? They're designed for large files and the implementation typically uses a 64-bit type as the base for fpos_t. … | |
Re: >i have looked all though my textbook and all over the >net and have not found any examples similar. You mean you haven't found any examples that do exactly what you want. I find it hard to believe that there are no examples that are similar, because I've written a … | |
Re: If string.h isn't allowed, I'm reasonably sure std::string isn't either. This is my educated guess based on the fact that the OP is using an old compiler that probably doesn't support std::string. :icon_rolleyes: | |
Re: >SRL 3.81 to SRL 4.exe has encountered a problem and needs to close. Classic runtime error. It means you're probably overrunning a buffer somewhere. Run your program in debug mode and step through it until you hit the error. That'll give you a good idea of where the error is … | |
Re: >well it is better if u can give straight 4wd answers... Salem's answer not only was as thorough as possible given the complete lack of information you provided, it was also useful in other ways. So drop the attitude. | |
Re: >I usually fix the errors first before I fix the appearance of the code. The appearance of the code helps you find errors, genius. | |
Re: >everyone here can give me the code of this sample program.. No, everyone here can tell you to do your own homework. We'll help you with it, but we won't do it all for you. Sheesh. | |
Re: As much as I love trees, I'm not keen on deciphering your code and then figuring out where you're lost. So I'll ask you to be more specific about what you want help with, and show you the structure code I use myself: [code] void jsw_structure_r ( struct jsw_node *root, … | |
Re: [code] for(int i= 0; i < 15; i++) { int column = 0; for(int i= 0; i < 12; i++) { gameBoard[i][column] = rand() % 9 + 1; } cout << endl; column++; } [/code] I'm not sure what you think this is doing, but it's not filling the table … | |
Re: Do you want us to install it and configure it for you too? Ooh, and should we use it to write all of your programs as well? Why don't you pick out a compiler first, then try to install it yourself. Then if you have problems, we can probably help. … | |
Re: >I need the function flip() to return the value of heads and tails back into main, without using any arguments. Why can't you use arguments? Functions can only return one value. Unless you put the heads and tails into some sort of aggregate type, or pack them both into a … ![]() | |
Re: >Using this would be better practice b=b-'a'+'A'; Since its not >necessary that you use ASCII character encoding always. You're splitting hairs when there's no difference at all. Both solutions are non-portable and rely on the setup of the ASCII character set. The latter is a better choice [I]only[/I] because it … | |
Re: >how?? Probably with string input. With over 20 posts, you should be aware of how we expect the Q&A process to work. You're a part of the process, which means we're not just going to tell you how to do things. You have to think about it yourself and show … |
The End.