949 Posted Topics
Re: It's quite easy actually. ;) The key is, when you exceed the maximum of a data type SOMETHING is going to go haywire. When you exceed a positive integer, it might go negative (or do something else). A simple while loop (or for loop) will get you "close". Just keeping … | |
Re: Try Pelles C (a free Windows only C only compiler), and you won't look back to Turbo C. There is a learning curve, but it's not bad at all. MUCH more capable. | |
Re: First, welcome to the forum, Rutwvu! ;) If you need to do a merge sort, why entertain the idea of using a bubble sort? Please don't do that! USE MERGE SORT! Bubble Sort is fine for < 100 things, but for anything else, it's just for entertainment unless the data … | |
Re: Welcome to the forum, Roflspanker! ;) I believe I see the problem, but let me set it up in my compiler. Your code tags were perfect - except one [ char got skipped, somehow. | |
Re: I used Turbo C with both C:\TC and C:\TC\BIN in the path (not a file, the directories). Had no problems, but my shortcut on the desktop changed me to TC\BIN for all work in the IDE. You may have other difficulties because Vista is more 32 bit, whereas I was … | |
Re: You probably don't want to delete a record - shocking I know. Simply zero out the main key (perhaps an ID number which can never be zero), and the last name, first letter, to an end of string char: '\0'. (It's strlen() will be 0 in that case) You actually … | |
Re: A couple of things: [CODE=c] for (i = 0; i < n; i++) << ; >> // This section of the code is meant to determine // whether the values in the array are odd or even. //remove the above semi-colon from the for loop oddcount = 0; evencount = … | |
Re: You will want to have three functions, imo: getInput(), main() to process the data, and printIt() to make your output. Right now, I'd start with those three functions, and make a file with the data, which your program can read when it starts, saving you the time and effort of … | |
Re: Filenames are char's, so fgets() is always one of the better choices: [CODE]fgets(charArrayName, sizeof(charArrayName), filePointerName);[/CODE] It adds a newline onto the end of the string, but it can be readily removed if you don't want it there: [code] int len = strlen(charArrayName); if(charArrayName[len-1]== '\n') charArrayName[len-1]='\0'; //overwrite the newline char by … | |
Re: You might have opened too many files, at one time - I mean perhaps you kept opening files, and not always closing the previous files, and continued opening more files. On most compilers, C has a limit of 256 files being opened at any time: 0 to 255. (if the … | |
Re: Oh yes! Nothing personal, but I really dislike your code: 1) It's int main(void) or int main(int argc, char *argv[]), never just main or void main. And always with a return (usually zero) to signify success to the OS and you. 2) Your indentations are an affront to real estate … | |
Re: There are two basic types of algorithms to solve Sudoku: 1) Brute force - relies on making guesses, and typically uses either backtracking or coloring. "Dancing Links" algorithm is especially elegant, imo. 2) Use human type reasoning methods which limit guessing It is FAR easier to use brute force with … | |
Re: That depends on what the program does: If it's running the auto pilot of the jet I'm on, I'd like it to work exactly correctly, thank you. ;) Even when safety isn't an issue, just imagine the waste from having printing software that goofs up 50000 copies of a book … | |
Re: Hey, Remove the ampersand & from the scanf() line of code. Strings don't work with that, just numbers and stuff. Your char arrays are very small. Remember that all strings need a space for the end of string marker: '\0', which scanf() will try and place onto the end of … | |
Re: A good simple way to do this is to always use two nested for loops: [CODE]An outer for loop to control the row variable(s) and an inner for loop to control the printing on that one line currently being printed. [/CODE] Think of it like you are always going to … | |
Re: I can't answer your query, but I know who can. ;) In chess, they use(d) a recursive version of mini-max called alpha-beta (which is just mini-max with a few lines of code to improve it). Then, along came multi-core processors, and everyone wanted their chess program to run "deep" in … | |
Re: Looks like you want a bitwise or | Check out this tutorial and see if it doesn't get you started: [url]http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/bitwise.html[/url] | |
Re: Sorry, Gnomelook. This isn't a short order homework helper site. Here, as on most programming forums, it's up to YOU to start your assignment or project. When and if you hit a snag, then post your code or pseudo code, and we'll try to help get you past it. But … | |
Re: Can you draw arcs by modifying the algorithm? yes. But you can't use the neat algorithmic trick of the circle drawing algorithm, to that same exent (all four quads at once). Maybe define a midline and try using both sides of the distance from that midline. I'm thinking of a … | |
Re: With two for loops, one nested inside the other. The outer for loop manages the rows, and the inner for loop manages the variables for the columns inside the row being printed. Remember that the total width of the diagram, minus the number of stars you print on that row, … | |
Re: I'm using Pelles C (it's free), and has it's own small forum for really good advice. It's only C, and only for Windows, 32 and 64 bit, and the IDE is more intuitive, imo. | |
![]() | Re: Describe your array, and which way you want to "flip" it - Rotate it 90° clockwise or counter-clockwise, or along a particular axis (specify which one). A 3 X 3 example of the array before and after the flip, would be great. Use code tags around the example, or it … |
Re: I have never understood the desire to swap out the pivot/key in Quicksort. It's not necessary. Your version has no if statement before the recursive calls, to allow it to always choose the smaller sub array. With a recalcitrant data set, you might run out of stack space. This is … | |
Re: You only need two for loops, one nested inside the other. The outer for loops handles how many rows, and the inner for loop handles the printing on that row. [CODE] for(r = ....etc ) { for(c = ....etc ) { with every loop you'll either add or subtract one … | |
Re: Welcome to the forum, Str91! ;) The way programming forums work is, you get the ball rolling on the assignment, and then come back when you can describe a particular problem - preferably by posting code and asking specific questions about whatever is the problem. That saves us a boatload … | |
Re: There is realloc(), but it's not available for declared arrays, just allocated ones. But you can malloc or calloc a new array, and then transfer the old, into the new array, yourself. Doing it yourself, gives you a better chance at understanding the process - good for a student. No … | |
Re: Whoa! This is no way to code! Take a break from the keyboard and learn how to work with arrays a bit more. This:[CODE] char* stringArray3 = [COLOR="Green"](char *)[/COLOR] malloc (sizeof(char));[COLOR="Red"];[/COLOR] [COLOR="Red"] free(stringArray3);[/COLOR] [/CODE] Is mind-numbing stuff. After you free an array, it's GONE to Byte Heaven (or Hell), and … | |
Re: "Get it to work right", is THE most vague description of the problem! C'mon! Put some specifics into it. FCOL! | |
![]() | Re: Some food for thought: [CODE]/* 7 aluminum .012580 .003000 32. 1130. cast-iron .005441 .001747 32. 1160. ingot-iron .006375 .001636 32. 1380. malleable-iron .006503 .001622 32. 930. ingot-steel .006212 .001623 32. 1380. copper .009278 .001244 32. 1160. nickel .007652 .001023 32. 1830. */ #include <stdio.h> int main(void) { FILE *fp; int … ![]() |
Re: Try <= in your comparisons. Without at least one of them in in that if statement, my version of Quicksort, goes into an endless loop. [CODE] /* Split the array into two parts */ do { while (A[i] < pivot) i++; while (A[j] > pivot) j--; if (i<=j) { //without … | |
Re: Wrong format. Use: [CODE]filePointer = fopen("filename", "w");[/CODE] Your file mode letter can be "r", "w", "a" "rt", "wt","rb" or "wb". The one's with a b are for binary mode, t is for text (and your system may have a default set by a variable option for your system). You can … | |
Re: You can use a for loop. Say you want to work through 3 sorting functions, with two different sorting sizes. [CODE] for(i=0;i<6;i++) { if(i<3) ram2get = 10000 else ram2get = 1001001 allocatemem(ram2get); genRandomNums(ram2get); if(i==0 || i==3) bubblesort(); else if(i==1 || i==4) Combination(); else if(i==2 || i ==5) Insertion(); //this will … | |
Re: For finding larger primes, quicker: 1) #include <math.h> 2) in the outer loop, save the sqrt() of the number being checked, add one to it 3) in the inner for loop, stop at < that number you just saved. You never need to go any higher. 4) if you have … | |
Re: That thread is 4 years old, so I doubt any answer will be forthcoming. Please let old threads rest in peace, and start a new thread - hopefully with better communication skills than was used here by Natnit. | |
Re: This is a common job that can be done in different ways, but the easiest one is probably using fgets() to read every line of the file (this a text file, right?), and then searching for the pattern you want, within that buffer. It would start like this: [CODE]#define MAX … | |
Re: Step back from your keyboard for a sec and think about the area that needs to be searched. One is a divisor for every integer, so you can start with 2: n1 is the first candidate divisor, n2 is the second candidate divorsor. Product is n1 * n2. Number is … | |
Re: Oh Good Grief! Change your program, to generate all the prime numbers up to the number the user puts in. Then you'll get on the right track with this. This is out in the weeds. A better challenge would be to find all the lowest 10,000 primes, and use a … | |
Re: Why don't you read up on the cipher at Wiki: [url]http://en.wikipedia.org/wiki/Rail_Fence_Cipher[/url] and give it a try. It's not as hard as it might look. Do a couple messages by hand, and you'll see. I'm sure that several posters could give you a hand with it, when you have a specific … | |
Re: Control+Z (aka ^Z), is the end of file indicator, for DOS and Windows (all versions). It is an integer, and can't be detected as a char. So there's your while (or for) loop: [CODE]while(first integer != EOF) { //your code here } [/CODE] Whenever possible, use integers as your data … | |
Re: Remove ch == ' ' from the else if portion of the code. Unless a char has been printed first. So you need a counter that is reset whenever a newline is printed. If the counter is zero still when it finds a space, don't have it print the newline … | |
Re: I suggest this way. It's just the way I'd do it by hand, with paper and pencil. Get the floating point number, and if it has one digit after the decimal, multiply it by 10: numerator = 52 (5.2 * 10) denominator = 10 Now work in your loop, to … | |
Re: If you OS is Windows, you can use the Windows API for it, but you can also use the conio.h include file features, in DOS or Windows, up to the 16 bit code limit. (That is, the 64 bit versions of Windows won't run Turbo C code, without an added … | |
Re: b, c, and d are yes. e) is no, because a backup program will be able to make incremental backups, and save a LOT of disk speace, on the portable drive. Consider also that some files may not need to be backed up at all, because they haven't changed since … | |
Re: Read up in your help files, on how int's with assigned values that begin with a zero, are interpreted by your compiler. What would an assignment of 080 print up? | |
Re: First, Welcome to the forum, Susees! ;) Second, Always use code tags around your code - otherwise it's very hard to study your code, because the forum software uses the wrong fonts, and squishes it all over to the far left hand side of the page. In your call to … | |
Re: Shell sort is Insertion sort, with an added outer loop that allows values to be moved a longer distance, in one loop, when it's advantageous. As the gap in the outer loop is reduced, Shell sort becomes more and more like Insertion sort. In it's last time through it's inner … | |
Re: No malloc needed, but there are always ways you could use malloc, of course. Think of a 2D table: Floor space numbers =================== [CODE] [row 0 of the table] [1 = occupied, 0 = empty space] 1 2 3 4 5 6 7 8 9 10 << element number 1 … | |
Re: Welcome to the fourm, Huzaifah! ;) The way programming forums work is that you FIRST need to show what you have done, and then ask specific questions about any problems you have found. We help people with programming problems, but they have to show they're actively working on it. Otherwise, … | |
Obviously, it should be titled: "Steak and Chicken Dinner Problem" A wedding reception will have 200 guests and the dinner budget is $9,000. [CODE]Wedding Catering Prices: =================== Chicken Dinner: $40 Steak Dinner: $50 [/code] What is the highest number of steak dinners you can serve at this reception, and stay … | |
Re: And you called this a seg fault on a bubble sort, why?? Anyway. I don't use merge sort much, but p+q/2 will be processed as p + (q/2), and I don't believe that's what you want. I use an m (middle) variable, myself. l(left) and r(right), correspond to your p … |
The End.