949 Posted Topics
Re: Not scanf("%c", &someVariable), but scanf(" %c", &someVariable); The %c format needs a space before it, to "eat" the newchar char, and get past it. | |
Re: You posted this last week, and I replied with several questions, which you never answered. 1) What code are you using now? There are three different sieve algorithms for primes, which one are you using? Eratotheneis? Please post it. 2) What run times are you hoping for, and what run … | |
Re: That isn't what we do here. ;) We help YOU when you are stuck with some C programming problem, but we don't supply algorithms or large blocks of code for you, on request. You get started on your program, and if you hit a problem you can't solve, then you … | |
Re: strstr() does exactly what you want, returning a pointer to the first char of the target string it finds. If the target string isn't found, strstr() returns NULL. Wasn't that easy? ;) if(strstr(string1, targetString)) { //code to handle a target string that was found }else { //code to handle where … | |
Re: The best way to simplify a program, is to refer back to your logic you used to create it. That might be your flowchart or pseudo code - or just a diagram on a napkin. Whatever you used to create the logic for this program. Now ask yourself, "Are there … | |
Re: Sourceforge has a lot of projects, but I like the puzzle type problems myself. Try ProjectEuler, SPOJ, etc. Some of those problems are REAL "projects". | |
Re: Have you created the products.txt file yet, with the necessary spec's as you describe here? 1. The product IDs and product prices are stored in a table format in a file named products.txt. Create a text file in the same folder as your .c file and type in two columns … | |
Re: Most common problem in C - the hidden newline when dealing with a char Add one space in scanf(" %c", etc.), and all will be well. The space in the format string, tells scanf() to go past any whitespace, including a newline. | |
Re: First, Welcome to the forum, lp94! You need to start your program, and then ask for help, on specific problems. We weren't in your class, and this is YOUR assignment. Think of it as though you had no computer. How would you start this with just paper and pen? Give … | |
Re: That is a LOT of primes! ;) You were using the simple "test by mod" for a remainder, before? Before I suggest something, give me: 1) info about your time requirements. Is there a time limit of some kind? 2) info about the system that is running this program. What … | |
Re: Your character should have struct members which define all his attributes in any given area. If not, the area should have that info, so your player has everything he's earned, wherever he goes (some of it may not be functional in some area's, but he still has it). | |
Re: You googled for "node deletion in binary trees in C", and received NO hits? Without code, I have no idea of why your logic isn't working. | |
Re: You can use strstr() (searches for a string, inside a string), to search each line of the file, as it's read. That will hugely simplify your program. Work with code based around logic similar to this: char *pstr=NULL; char line[80]; char target[12]; //plenty of room is good FILE *fp; //open … | |
Re: Make your printf() format, occupy 80/number of columns you want to have including spaces between columns. If I want 4 columns, I have my printf() format use 20 spaces, etc. #include <stdio.h> int main(void) { int n; for(n=0;n<200;n++) { printf(" %18d ",n); //4 columns, each one 18+2 wide. } printf("\n"); … | |
Re: The nested two for loops are usually the easiest way to make designs with rows and columns. You just need to see the pattern that is used, to make the design you want. Use the outer for loop for the row control, and the inner for loop to control the … | |
Re: First, Narue is a "ma'am" not a "mister", and what we do is help people with their C code. You post your code, and say what's not working right, and we try to find out what's wrong with it. There are homework sites, but this isn't one, "per se". We … | |
Re: What is "arrayList", and why are you copying Letters + 2? IMO, you should be using strcpy(), instead of strncpy(), since the words will have different lengths. | |
Re: Because in the search for an answer, your algorithm should always favor the larger numbers, in the search for the password. Smaller numbers get lower priority. http://en.wikipedia.org/wiki/Greedy_algorithm | |
| |
Re: There is an excellent PDF document on Quicksort, freely available. I got it from Googling for Quicksort. The choice of a pivot in Quicksort is crucial. Best choice I have found in many tests, is using (left + right)/2. It's faster than median of three, and gives better sub-array distribution … | |
Re: Google for "algorithms in C", for starters, and check out Wikipedia's algorithm's, as well (they have LOTS). Flowcharts are harder to find, (just not that popular on the internet, I believe), but give all your search engines a shot with that subject matter, as well. "All", you will never get, … | |
Re: You made me laugh with your post to convert decimal to hex, including "A,B...G" *G* ?? :D Anyway, your algorithm to change decimal to hexadecimal is wrong. Here's a modded version of your program, which shows what the hex value of a decimal, should be: [code=C] #include <stdio.h> int main(void) … | |
Re: On lines 33, 41, 122, etc., you have put two "==" (a test for equality), instead of just one equal sign, (for assignment). Turn on your warnings on your compiler, and you'll be told all this and more. Variables x and y are never used in survivalRule(), birthRule(), etc. Life[][] … | |
Re: In C, ALL parameters are passed by copying - NOTHING ELSE. When you copy an address (pointer), you have a way of affecting the original variables that are pointed to by the address - so it's a pass by reference, in it's effect. You pass a 2D array to a … | |
Re: We would hope that you will tell us what is the problem with the program - then we can focus on a specific spot within your program, to look for errors. Saves a lot of time, that way, and gives you a chance to develop some better problem solving skills … | |
Re: A better solution is to count up how many values you're putting into your array. For instance, what if the lowest value was zero? What if you have no idea what the lowest value might be in the data? The better logic is: 1) count the number of values you … | |
Re: First off, I'm not sure, OK? For smaller numbers, I'd suggest looking into bit shifting, and how each shift leftward, multiplies by 2. Bit shifting is among the fastest operations on a computer, in C. 00000001 = 1 00000010 = 2 00000100 = 4 etc. But your number far exceeds … | |
Re: Why not add a print statement with two getchar()'s afterward (to pause the screen) the first time through the loop, and print out exam[0] and correct[0] and see what's going on? It looks right, but sometimes the errors are just too simple to catch with a look through. Are you … | |
Re: isalpha() tests only ONE char - not a whole string. You'll need to loop through the entire string with either a pointer, or an array index, to test each value in the string, one at a time. | |
Re: String compare (strcmp()), compares strings, not a string and a char. Remember what a string is - a group of contiguous char's, with a terminating NULL char (generally written as '\0', but sometimes just as a 0 (zero). So '+' can't work - it's just one char. "+" could work, … | |
Re: You shouldn't code like that. Be specific in what you want the compiler to reserve for space. In fact, if you create an array, and it has almost no space, you can "get away" with overrunning it, by several char's, or pointers to char's, even integers. Usually about 7, but … | |
Re: It used to be necessary, but that has been deprecated for a long time now. You should NOT cast the return from malloc (which is a void pointer), because it is automatically right for every data type. There are cases where the data type is not a basic type in … | |
Re: Break it down: 1) you'll need to have a loop to generate the fibonacci sequences, and 2) you'll need to have logic to save the bit pattern of the number the user input, before your program enters the loop mentioned above. Once you get that working, the rest is entirely … | |
Re: I'm not sure why you want to delete white spaces?? This is a two year old thread, so it's best to start a new thread, and perhaps tell us what you are trying to do, in more detail. If you will show me your code, I will show you mine. … | |
Re: Your problem is an example of an "exact cover" problem. Google that and read up. Any references to "DLX" or "Dancing Links" or "Algorithm X" typically noting Knuth, you are wise to skip - that is a very complex algorithm. Think of your L shaped "tiles". Nevermind the blank square … | |
Re: Here's how I approach this problem: 1) sort the letters you have, lowest to highest. I always want the permutations to start with the lowest possible one, and work up to the highest one, and be in order. And have no repetitions. 2) You will work from right to left, … | |
Re: Personally, I'd use fgets() to get the whole line of text from the process file: fgets(charBufferName, sizeof(charBufferName), filePointerName); which easily gets 1 line of data, and in a while loop, gets every line of data: [code] int i=0; while((fgets(buffer, sizeof(buffer), fpName)) != NULL) { //then use sscanf() to get the … | |
Re: As a beginner in C, you DEFINITELY want to use an array of chars for the words: words[NumberOfWords][40]. Where NumberOfWords could be just a few hundred or 40,000 or more. There are very few English words that are longer than 39 letters, (save 1 space for the end of string … | |
Re: I see your code makes comparisons with doubles - which is quite hazardous. Floating point numbers can't represent all values - they have to (very closely) approximate some of them. The "cleanest" way to work with numbers that must be compared, is to use a multiplier, and then cast them … | |
Re: The compiler will handle that, for any data type, automatically. It's a bit awkward because you're working with mid and other variables, as pointers, instead of as an index. Also, you repeat the calculation and assignment line of code for mid, twice. Move it to the top of the while … | |
Re: The biggest improvement in run-time is always found by choosing the right algorithm - the logical steps that will be used by the program, to find the answer. Then there are optimizations beyond the algorithmic one's, which I'd call "machine and language" optimizations. This program appears to need both of … | |
Re: [QUOTE=snivas519;1304276]ya...i can do...but it requires a file to store the user data...[/QUOTE] Welcome to the forum, Snivas! As for the file being needed - <wink> <wink> I KNOW you were joking. Please God, that's all I ask for today, let Snivas be enjoying zee little joke. ;) | |
Re: Your program plays the puzzle, but it doesn't play it as smartly as it could. The puzzle is all about the first player taking the initiative, and keeping it. If player1 does that, he can always win the game. If not, he can be made to lose, every time. It's … | |
Re: Line 14: totalsquares is being calculated from an uninitialized variable. Declare totalsquares, and don't give it a value until AFTER the user has entered the Nsize value. Line 20: Same thing with calculating i and j - do that AFTER Nsize has been entered. The malloc just seems wrong: [CODE]array … | |
Re: [QUOTE=mridul.ahuja;1707932]Hey you can use turbo c in windows 7 by changing its compatibility.. I changed the following settings to make the window larger : [COLOR="Red"]FONT > [/COLOR] [COLOR="Green"]Size = 28 Font = Consolas[/COLOR] [COLOR="Red"]LAYOUT > [/COLOR] Screen Buffer Size : Width = 80 Height = 75 Window Size : Width … | |
Re: This is the basic format type of code. (It's actually from another post on this forum). I like using fgets() to put a row of text into a char buffer array - just make sure it's plenty bigger than the longest possible row of input. Waste a little memory here, … | |
Re: If the data is in a file,I'd use fgets() to get each row, then strstr() to look for GET in any row, and sscanf() to save it into the variable that you want. | |
Re: Welcome to the forum, Kgal! ;) Your last row in G[][] is missing a digit. So you want to change the name of the array the data is going into, in the outer loop of the input? [CODE]for(each array) { //change array names with every loop for(each element to be … | |
Re: So far, you haven't shown any of your own work - and copy and pasting the requirements of the project, certainly doesn't count as work on your project. So we have no idea what you're stuck on. Get started on your assignment, and when you get stuck on something, post … |
The End.