949 Posted Topics

Member Avatar for ntggl19

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.

Member Avatar for ntggl19
0
202
Member Avatar for nitin1

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 …

Member Avatar for Adak
0
112
Member Avatar for pooja.singh.3950

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 …

Member Avatar for Adak
0
114
Member Avatar for jcmoney1010

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 …

Member Avatar for Adak
0
181
Member Avatar for praneeth_gunda

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 …

Member Avatar for elava
0
501
Member Avatar for Delnith

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".

Member Avatar for Schol-R-LEA
0
234
Member Avatar for omarelbeik

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 …

Member Avatar for Adak
0
318
Member Avatar for kieranrea

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.

Member Avatar for somjit{}
0
158
Member Avatar for lp94

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 …

Member Avatar for Adak
0
149
Member Avatar for nitin1

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 …

Member Avatar for Adak
0
80
Member Avatar for gotto

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).

Member Avatar for Adak
0
159
Member Avatar for rithish

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.

Member Avatar for Gonbe
0
143
Member Avatar for DavdPrez

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 …

Member Avatar for DavdPrez
0
2K
Member Avatar for ronnel09_1

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"); …

Member Avatar for Adak
0
227
Member Avatar for Brigadier

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 …

Member Avatar for Adak
0
117
Member Avatar for suhrud.l

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 …

Member Avatar for c1c2c3c4c
0
245
Member Avatar for HelloJarvis

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.

Member Avatar for dx9_programmer
0
248
Member Avatar for nitin1

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

Member Avatar for Adak
0
131
Member Avatar for dasdsaasd
Member Avatar for rithish

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 …

Member Avatar for maurya10
0
351
Member Avatar for ayoub

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, …

Member Avatar for WaltP
0
2K
Member Avatar for campuzcrazyness

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) …

Member Avatar for bmsangati
-1
1K
Member Avatar for acsusf12

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[][] …

Member Avatar for prestonk98
0
247
Member Avatar for chirag_mittal

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 …

Member Avatar for chirag_mittal
0
436
Member Avatar for SavemeEddie

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 …

Member Avatar for Adak
0
157
Member Avatar for zingwing

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 …

Member Avatar for Adak
0
232
Member Avatar for gourav1

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for TarkiB

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 …

Member Avatar for TarkiB
0
220
Member Avatar for tubby123
Member Avatar for ilovephil

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.

Member Avatar for Adak
0
192
Member Avatar for ilovephil

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, …

Member Avatar for Adak
0
123
Member Avatar for tubby123

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 …

Member Avatar for Adak
0
1K
Member Avatar for tubby123

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 …

Member Avatar for tubby123
0
165
Member Avatar for swissknife007

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 …

Member Avatar for Adak
0
107
Member Avatar for Alfy

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. …

Member Avatar for zeroliken
0
2K
Member Avatar for brendono978

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 …

Member Avatar for D_Unforgiven
1
494
Member Avatar for gourav1

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, …

Member Avatar for subith86
0
106
Member Avatar for Lillylionhert

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 …

Member Avatar for Lillylionhert
0
5K
Member Avatar for Xinen

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 …

Member Avatar for Adak
0
137
Member Avatar for ben25x

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 …

Member Avatar for Adak
0
174
Member Avatar for vegaseat

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 …

Member Avatar for codinghavok
1
769
Member Avatar for gourav1

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 …

Member Avatar for gourav1
0
316
Member Avatar for mohan_198505

[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. ;)

Member Avatar for dij_0983
0
506
Member Avatar for manjeet593

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 …

Member Avatar for Adak
0
135
Member Avatar for cka91405

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 …

Member Avatar for Adak
0
278
Member Avatar for rithish

[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 …

Member Avatar for Schol-R-LEA
0
409
Member Avatar for alphahuman

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, …

Member Avatar for Narue
0
1K
Member Avatar for purpleturtle_97

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.

Member Avatar for Adak
0
268
Member Avatar for kgal

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 …

Member Avatar for Adak
0
167
Member Avatar for UNDER-18 FG

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 …

Member Avatar for Adak
0
162

The End.