949 Posted Topics
Re: That's not how the forum works. We aren't a "do your homework for you" forum. We are a free "help you out when you get stuck on your homework, and show real effort", forum. [B]It's all up to you to get the project started[/B]. It's a pity you have no … | |
Re: Books are prone to doing this ( putting function definitions before main() ), because it saves them space in every program they print. I always like main() first, then all functions go in alphabetical order, with function declarations in global space, unless the function is used entirely as a helper … | |
Re: Make your output screen a tiled window, before you start the program. If you need to see more of it, use your mouse, only. Obviously, you can't leave keystrokes in the input buffer, and not have it affect your program, which relies on the keyboard input buffer. | |
Re: Off hand, I'd say use a two dimension (rows and columns) array of chars. Put the filename in the first chars, and then a space, and follow that with the keywords. Each keyword also separated by a space. FileName1 dogs type hounds terriers setters herding toys FileName2 horses type Quarterhorse … | |
Re: printf returns the number of chars printed, and you didn't print any objects, so it would return a negative number, as an error IF your compiler allowed it to compile. Perhaps you were thinking of: [code] if((ch = printf(something here)) > 0) //semi-colon or other code goes here [/code] That's … | |
Re: DOS had a path environmental variable, in a file named "config.sys". Windows has something similar, sometimes it uses config.sys, and sometimes it uses another file, depending on the version. The registry also has data on this. Best answer is to look up PATH in your Windows help, which will have … | |
Re: [CODE] #include<stdio.h> #include<conio.h> #include<string.h> int x; char name[20]; main() { printf("Exercise no. 10 ESN 211-9A MWF 7:30-9;30\n\n"); printf("Enter your age:\n"); scanf("%d",&x); if (x<18) printf("UNDERAGE!\n\n"); else if (x==18) printf("STUDENT LICENSE POSSIBLE\n\n"); else printf("PROFESSIONAL LICENSE AVAILABLE\n\n"); printf("Enter the result of your drug test: \n"); scanf("%s",&name); /* C doesn't support strings as basic … | |
Re: When you open a file, you receive a file position pointer (part of the FILE *, but not the whole thing). The file pointer has the address of the first byte of the file. If you increment that address, you can access any byte in the file, in sequential mode. … | |
Re: Your functions are not really functions, since you put a semi-colon on the end of their first line, in your program. I've fixed that for you, and made some important notes in this code, for you. The function main() should not be called, inside your program, as noted. Also, all … | |
Re: Welcome to the forum, Wurdig! ;) Remove the switch case. It just makes things more difficult. You'll need two nested for loops. The outer one will range from 0 to < MaxRows. The inner for loop is for the columns in one row, and will range from 0 to < … | |
Re: Try "cd..", to get back to the next higher level directory (parent). After the cd, if you don't use the two dots, you should specify the directory name you want to change to. Try "dir", instead of "ls". What OS are you using? | |
Re: Windows puts constraints on what you can do in this regard, depending on the version of Windows you are running. You are very likely to crash either the TSR program, another program running at that time, or even Windows itself. Modern way to do this, would be to use a … | |
Re: This is your original code (in code tags, please use them): [CODE] char *dic[][40] = { "atlas", "A volume of maps.", "car", "A motorized vehicle.", "telephone", "A communication device.", "airplane", "A flying machine.", "", "" /* null terminate the list */ };[/CODE] The square brackets here: dic[B][COLOR="Red"][][/COLOR][/B][40], are not necessary. … | |
Re: [B]Welcome to the Forum, 1150! ;)[/B] Scanf() leaves a newline in the keyboard buffer, and it's throwing a monkey wrench into gets(). The fix is to add this, right after the scanf() line of code: [CODE]getchar(); //pulls off one (newline in this case), char.[/CODE] | |
Re: Your logic should answer the kid's annoying questions on long trips: "Are we there yet?" [code] while(1) { if distance == goal) { stopWalking(); printf("Goal reached\n"); break; }else { takeAstep(); //assumes each step is 1 meter printf("I have %d more meters to cover\n", --distance); } } [/code] In humans, walking … | |
Re: Try it, it won't bite you. ;) To learn to be a problem solver, you have to explore the world of code - roses and thorns, as well. | |
Re: Are you using a C compiler, or a C++ compiler? In C++, &n would be a reference to n. I'm unsure how a C++ compiler would handle that reference, in a declaration. In C, a declaration of &n is an error. These are the errors I get from my Pelles … | |
Re: Welcome to the forum, Bubbinos! ;) Change your logic. Start with the array of numbers, being assigned to the array: [CODE] for(i=0;i<52;i++) { //eliminate repeated numbers array[i] = i; } //now pick a random card for(i=0;i<(NumPlayers * 5); i++) { j = rand() % 52 + 1; //range of 1 … | |
Re: There are two ways: 1) Use a big number library. GNU's is well known. 2) Use an int or char array. Make each element hold just one digit of the number. Write a function for each operation you want done. Yes, you might want a matching array, just to hold … | |
Re: Use fgets() to take in at least one line of text, at a time, into your buffer. Then use strstr() to look for the target word, in the buffer. You don't want to do this, char by char. To make it more efficient still, search for string search in Wikipedia, … | |
Re: Welcome to the forum, Jamblaster! ;) Always click on the [code ] icon and when it puts two code tags on your reply page, paste your code, between the code tags - easy to do since it puts your cursor right between them for you. All comparison sorts except for … | |
Re: What is your field (struct member is also a field), separator? Hyphen, space, maybe both? Here's a trick: Initialize all your fields in the struct to 0 or '\0'. Print out some strings. Put a vertical line between each field, with a pencil |. Now you can loop through the … | |
Re: No, this something you can easily do yourself, and just involves a bit of problem solving. You NEED to develop your problem solving, or you can't program worth a darn. Work through it by hand, and see what kind of loops you're using! Put some sweat into it! ;) Don't … | |
Re: If you ONLY want a C IDE and compiler for Windows only, I'd recommend Pelles C. It is ONLY for C, and ONLY for Windows (32 or 64 bit, so XP or Vista or Win7 are all fine). I like it! ;) | |
Re: And don't be like me and keep trying to add an s into that format specifier! ;) | |
Re: First thing - are you getting any warnings from your compiler? And do you have your warning level turned up high? Second, try checking the return addresses that malloc is giving your pointers. Are any of them null (indicating a serious problem)? Third, cut down on the space where the … | |
Re: You can't compare strings - you have to compare each char, one at a time. Include string.h and use strcmp(string1, string2). strcmp(string1Name, string2Name) will return one of three values: 1) a positive number 2) zero 3) a negative number That return tells you what the comparison of strings revealed: 1) … | |
Re: You're trying to print to the file or buffer, from within the IDE, aren't you? That's not what you want. Run it from the command line. Open a terminal (aka text window, command line interface, etc.) window. If you are not in the same directory as the exe of your … | |
Re: Try this: [CODE]//Before main() define a struct with struct countries { char name[50]; int numNation; } //now make an array of these structs, in main() struct countries nations[500?]; char myNation[50]; //and read in your data from a file, into the array of structs. //Now a for loop can replace all … | |
Re: I haven't read through all the above posts, but here's my ideas: 1) Use structs for each player, and struct members (fields) for each attribute you need. 2) KISS. Don't go Rube Goldberg here! You don't need a damage attribute, because when a character is damaged, his strength or life … | |
Re: fflush() on any input stream, like stdin, is deprecated, so it may very well not work at all. Use it on output streams only. ("Flush the toilet, not the kitchen faucet.") To pull the remaining newline char off the input stream, you can use: [CODE]getchar();[/CODE] right after the scanf() line … | |
Re: This is an OOP based program, and C has no OOP support. So, you need to post this in either a Java, or maybe even a C++ forum. Definitely, not here. | |
Re: Sorry, little bee, but we won't do your homework for you. This is a forum that tries to answer questions and problems relating to C. I'm sure your grade will be reviewed, and reflect the amount of work you put into it. You might try browsing through the "Computer Science" … | |
Re: You're trying to shove a first and a last name, into the same variable, name[]. That won't work. You can fix it easily a few different ways: [CODE]char lastname[30]; char firstname[30]; [/CODE] and then scanf() for the lastname, and for the firstname[] (or lname and fname, whatever). Or you can: … | |
Re: First, decide on the appropriate data type for each input and output item. Each of them will need to be a variable (a few might be removed later, but for now, plan on one variable per item, for input and for output. All variables should be local to main(), or … | |
Re: OK, this is the part of the help where YOU help US understand WTF you want. We weren't in the classroom, or heard the lecture, or read the text, or even know the teacher. First - find out what you want to do. Your info here just isn't enough to … | |
Re: If you have your data in the format you want, then don't convert it any further - C'mon! ;) You can read your hex data in as a string using fgets(buffer, sizeof(buffer), filePointer); Make sure that buffer has at least two char's more than the longest string of hex. One … | |
Re: Zia, welcome to the forum! ;) First thing you have to know is to ALWAYS highlight your code and click on the [ code] icon in the editor window. (it won't have a space before the c). Otherwise, your code will all be squished over to the far left, and … | |
Re: In Pelles C it's under the Source pull down menu, then select "view line numbers". Check around your IDE editor options, also. Not every IDE editor has this, for an option. | |
Re: I would learn the basics of the C language first. Can't do anything without that. There are lots of C tutorials on the web, including one's for this forum, and other programming forums with a C section on them. If you just want to manipulate images, I'd use software designed … | |
Re: I don't see anything obvious, but I'm not familiar with this, either. If I were starting to debug it, I'd probably start with assertions to check that all the indices are staying within their proper ranges. Then start checking the subtotals, and whether j=0 is correct, for it's initialization (or … | |
Re: Take in the telephone number as a string. Scan over the chars, and remove any hyphens or /'s. If any char in the string is unwanted, then [CODE]for(each char from that point, to the (end -1) of the string) { assign i+1 to i, in the array } [/CODE] and … | |
Re: [QUOTE]The problem is at some distance before they pass (at t2) they will have sufficient velocity to pass each other on the next iteration (t3). At t3 the distance will not be the same as t2 causing the deceleration to be different. [/quote] You may not care what the velocity … | |
Re: After EVERY scanf("%c...), when you are storing a char data type, add this: getchar(); Right after it. OK, the last one in the whole program, you don't need to add this line of code. What it does is remove the newline char that scanf() always leaves behind in the input … | |
Re: LevyDee is right IF the array had been sent to another function. In the function it was declared in, it will have size 10. Tubby, the union has ONLY a size big enough for the largest member. THE largest member, not the SUM of all the members. That would be … | |
Re: In C, the name of the array, is ALMOST the same thing, as a constant pointer - and it points to the first element of the array - array[0]. So [CODE]char a[] = "Hello there.";[/CODE] now the address of a, is the address of a[0], and a string operation includes … | |
Re: userinput[2] == userinput[2] ?? C'mon! ;) When you have a complex line of code, break it up into multiple lines of code, so each line of code is easier to understand, and debug. | |
Re: How about a new line 11 1/2: [CODE]if(expression=='q') break; [/CODE] You should have a getchar() in your code, (maybe line 11 3/4ths, to remove the newline that scanf() always leaves behind. |
The End.