949 Posted Topics
Re: It's hard to take your request seriously when you post up some code that won't even run. There are lots of other posts on this subject, here and all over the net. Also, check out the Sieve of Eratosthenes, on Wikipedia, etc. Come back with a full program, and then … | |
Re: Morse code has no equation or algorithm to figure out it's series of dots and dashes. It was made for brevity and ease of understanding, not computer algorithms, unfortunately for us. ;) | |
Re: My eyeballs get tired just studying your code. ;) Instead of two arrays to convert letters from one case to the other, why not use toupper() or tolower() (part of ctype.h)? Another easy way would be to simply use the ascii values. Since there is a constant difference of 32 … | |
Re: Step through the code with a debugger, and watch the values of the variables, as they change. Use asserts and print statements as needed, to help you debug it. This is not a "shades of grey" thing. If your function is wrong, then find the bug. Troubleshooting code is an … | |
Re: ptr is being given a new address, in the assignment statement ptr=&val, in fn(). It no longer has anything to do with i. | |
Re: Break it down into a few big steps (amid smaller one's): 1) Get your connect 4 program using one thread, working PERFECTLY. No crashes, no illegal moves, etc. It's difficult to debug a multi-threaded program, so get the single threaded version of your code, working really spot on. 2) Now … | |
Re: I used a char array char filename[SIZE], and a char *extension = ".txt". I used an unsigned int for the number. As the program looped around for another filename increment, the file_num++, of course. iota() from ctype.h, was then used to put the number into the filename char array. Then … | |
Re: To fill the array with unique int's from 1 to 52, just use: [CODE] for(i=0;i<52;i++) array[i] = i+1; [/CODE] Then you can swap random indeces around, until it's all shuffled [CODE] for(i=0;i<someNumberAtLeast25;i++) { temp = array[randomInt]; array[randomInt] = array[randomInt2]; array[randomInt2] = temp; } [/CODE] Give that a try. ;) | |
Re: Clocks aren't as easy as they look. For instance, Sleep(N) gives you AT LEAST N periods of time - but note the "at least" part of that. ;) Because other programs and lots of Windows services (programs without a terminal window for output), are running, many times you'll get more … | |
Re: First suggestion is to Google for a C program called "Matrix". it uses this technique to simulate the graphics of the Matrix movie (falling chars), in the console window of your VDU. It uses pointer notation, but remember that this: *(myArray + i) is the same as myArray[i], so therefore … | |
Re: Please don't immediately cross post your question on multiple boards. This has already been answered "over there". :( | |
Re: det is a single char. You're trying to make it a string, and it can never be a string, since it has no room for an end of string char '\0' to go on the end of it. | |
Re: Well, phi isn't used in any of the "line" functions, so that can be deleted. I don't understand why you used 3.1423. Wouldn't 3.1416 be closer? It's a very nice program. My critique of it would be that's it's logic is not as simple as it should be. You used … | |
Re: The best way to start a program, is frequently to work it through by hand, on paper. How would you do this, without a computer? You might use a row of an order form, where columns denoted the features the order desk should have, with a sub-total of the price … | |
Re: In main() you [B][COLOR="Red"]MUST[/COLOR][/B] call the bubble() function, if you want the program to use that function and sort. | |
Re: The way this forum works is that YOU are responsible for posting up your try to solve the assignment/exercise. So post your code (and do paste it between the code tags you get by clicking on [code ] icon in the editor), and tell us what has you stumped. Regarding … | |
Re: Your code is very verbose, and overly complex. Try and keep it short, simpler, and thus faster. Like this: [CODE]void insertionSort(int A[], int lo, int hi) { int i, j, val; for(i=lo+1;i<hi;i++) { val = A[i]; j = i-1; while(A[j] > val) { A[j + 1] = A[j]; --j; if(j<0) … | |
Re: There are four arrow keys. Each gives two bytes, the first one is 0 or 0x00 in hex. The second byte determines which arrow key: 0x48, 0x4b, 0x4d, 0x50 for up, left, right and down, respectively. You should download an ASCII char and key scan code chart, if you don't … | |
Re: When you have several fields which all relate to the same object, you create a struct which will group the different fields (members of the struct), into one record (struct). Then you use the dot member to access any member of the struct: system.date system.type system.os system.version etc. Which you … | |
Re: No, I haven't heard of that one, but Google and Wikipedia have a lot of information on all kinds of ciphers. Wikipedia has an entire portal dedicated to Cryptology - neat stuff. With all the interest in protecting info these days, you should have no problem Googling successfully for it. … | |
Re: One = char is for assignment in C. Two == char's are used for comparisons. [CODE]if(variable == someValue);[/CODE] This is the pseudo code for a nested loop version of bubble sort: [CODE]procedure bubbleSort( A : list of sortable items ) n = length(A) for (i = 0; i < n; … | |
Re: Instead of using a number of arrays, I would use just one 2D array for the positions. Servo 0 would have all it's positions in order, on row 0, cols 0 thru N Servo 1 would have all it's positions in order, on row 1, cols 0 thru N Servo … | |
Re: You've put in the wrong tags. For links, no tags are needed, can you fix it quickly? After 30 minutes, you can't edit your post on the forum. Welcome to the wonderful world of pointers/addresses running amok! ;) | |
Re: [CODE] printf("Enter 2-character state code: "); scanf(" %c",&stateCode); for(i = 0; i < NAME_LEN; ++i) { if (custArray[NAME_LEN].state == stateCode); //this is the line I am having a problem with printCustArray(custArray[i]); } [/CODE] 1) You're instruction say to enter a 2 char state code, but %c will only handle one … | |
Re: What formatting works with printf(), will work with fprintf(), and the formatting that works with scanf(), will also work with fscanf(), and sscanf(), etc. Nearly all of the printf() formats, also work the same in scanf(). There are a LOT of formats for each of these. The right format for … | |
Re: You can use a modified bubble sort if you make two changes: When you find a char that needs to be swapped, you move the entire row of char's (the whole word). Instead of comparing one column's char with the column next to it, like the regular bubble sort, you … | |
Re: C/C++ offers several advantages: 1) some free compilers, as well as competing commercial compilers, and a huge base of libraries. VB has none of these, that I know of. 2) a huge installed base of trained C/C++ programmers 3) there are a wide variety of compilers. One or more, for … | |
Re: On older Windows (3.1 type), you need them, because it used the old 16 bit addressing memory mode. With newer Windows, you will have to remove the far designation, or you'll get an error, even if you're using an older 16 bit, version of a compiler. I use a very … | |
Re: Shows a nice animation. Just showing off, I believe - ;) | |
Re: So the advice that was given to NOT use gets(), and to USE code tags, was completely lost on you? Try again. ;) | |
Re: You didn't show a return type for the prod() function. Also, you didn't add the prototype to the function, before main(). The prototype is just like the first line of the function, but doesn't need the name of the variables, just the type. Put that below the include files, before … | |
Re: By convention, x and y denote a range of values in the horizontal and vertical direction respectively, on a plane. Taken together, they give the exact location of any point on that plane. Common name - coordinates or Cartesian coordinates. So draw yourself a graph and label some x and … | |
Re: The earlier posts are from 2009, so I doubt they will answer your questions. You need to start a new thread with your problem, and let this one be buried, again. ;) | |
Re: I don't know if you can do this in Excel easily, but it's trivial for a program to take your data, make these changes, and give it back to you. You know how to export a file from Excel, in text format? Do you know how to import a file … | |
Re: I would ask this in one of the MS usenet groups (in newsgroups). This issue must be affecting others. Your answer may be there waiting for you, already. In any case, you can get good answers, rather quickly there. Good luck. | |
Re: The phrase "C does not want to play ball", is not nearly as helpful in troubleshooting your program, as you seem to believe it is. ;) Use your debugger or add some printf() statements in your code, and give us the real problem you're seeing with your program. | |
Re: When you don't use code tags, your code looks like the dog's breakfast, and is generally ignored. Always highlight your code, and click on the [CODE ] icon in the top bar of the forum editor, to make your code easily readable. First thing I see wrong is the & … | |
Re: When I deal with a string like this, that just isn't "quite right", the first thing I like to do, is make it "right". [CODE]char str[]="1,3,5-9,10,12-14";[/CODE] One pass through a for loop would remove both the comma's, and replace the hyphens with a space. Then, use sscanf(), to get all … | |
Re: What have you tried? With linked lists, it's best to study it, and have a good sample program that you know works, to refer to while you are troubleshooting your own program. I would either refer to your class/book notes on it for this, or grab a none good program … | |
Re: So the struct will need two members, something like: [CODE]struct mystruct { char name[20]; char passwrd[10]; } [/CODE] Before main(), then in main(), create the struct itself: [CODE]struct mystruct mine[20];[/CODE] and now you have an array of twenty records. Pass mine around like any other array, to your other functions, … | |
Re: Ok, what have you tried to troubleshoot this? Have you tried sending the data at slower speed? That would be my first test. | |
Re: Each student will typically be taking several courses each semester, so adding more classes into your student struct, would not be unreasonable. Two other alternatives: 1) Add a classes struct, and nest it inside your student struct. The one I like best is an array of char, where each class … | |
Re: You made an array with only 1 row, 1 column, and 1 depth. Since arrays in C always begin with subscript 0, trying to refer to [1] in any dimension, is junk - you're out of bounds. ;) | |
Re: So your logic needs to consider the lowest number first, and then continue adding the lowest number, until it's >= 5. If it's == 5 then print it. Then you pop off the next number from the stack, and having backtracked to one for the second number, trying adding more … | |
Re: I'm thinking databases are not the topic for relative newcomers to take on. Why don't you Google MySql and see if that meets your needs? It's open source, and there's a ton of info on the net regarding it's usage. | |
Re: Double your getchar()'s, and all will be well. When you enter a char, you hit the the enter key, putting a newline ('\n') char into the keyboard stream (stdin). The first getchar() pulls off only the char you pressed BEFORE you hit enter, leaving the newline behind - and lets … | |
Re: Get a good IDE, and understand, it will take time and a lot of work to be a decent programmer. Learning C from the command line -- holy shit! Insane confidence killer, for a beginner. imo. | |
Re: Makes sense it might do this, doesn't it? First, it makes room for f[], then it makes room for g[]. Nothing in between is made, so it's quite probable that f[] is just beneath or above g[]. When you "walk" off the end of f[]'s boundary, what might you very … | |
Re: There's nothing wrong with your code - runs fine. There are some good C IDE's (integrated development environments), with editors, help buttons, and messages from the compiler and linker, and debugger. Visual Express from Microsoft is one, and Code::Blocks is very good, as well, although it's separate from the compiler. … | |
Re: The device you're working with, only works from top line to bottom line (unless you do some repositioning of the cursor, which is not needed here). print the top line of *'s in a loop: print the left side * print the spaces needed, then print the right side * … |
The End.