200 Posted Topics
Re: do { printf("|......|\n"); printf("|..c...|\n"); printf("|..ch..|\n"); printf("|..chm..|\n"); } while (0); | |
Re: Look into [WinSock](http://msdn.microsoft.com/en-us/library/windows/desktop/ms740673(v=vs.85).aspx) when programming on a windows platform and BSD Sockets for Linux. You can also use [Boost.Asio](http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio.html). [Beej's socket guide](http://beej.us/guide/bgnet/) is also a well-written source to learn how sockets work for a beginner. | |
Re: What does the &arr[i] do? I think it has something to do with pointers but I don't understand pointers either so I'm just trying to get the basics... You are (kind of) correct. '&' as a unary operator is used to obtain the memory address of a variable. For example, … | |
Re: You commented your code with some steps. You could say your program does the following: 1. Intialize random seed. 2. Generate secret number. 3. Play guessing game. (keeps starting guess attempts until guessed, tracks amount of tries) 4. Do guess attempt. (either right or wrong, involves asking the user for … | |
Re: Hmm bit-wise operators don't seem to be blacklisted. You could implement binary long division with them. | |
Re: Yes, and I like turtles. -edit- In case it isn't clear: What is your question exactly??... | |
Re: You'd have to resize your 2-dimensional array as you read the file. Initially you should allocate the array dynamically using malloc(). Then read from the file and when you run into array boundaries expand it using realloc(). | |
Re: There's quite a bit wrong in your code. 1. Note that 'int' is for storing integers. You almost seem to want to use it as an enumeration (enum keyword) but you don't initialize the values. When querying for input using '>>' it will try to read an integer because the … | |
Re: You can't say anything useful about the code, only that it results in undefined behaviour; you're writing to the same variable twice or more without an intervening sequence point. See section J2 and section 6.5 [here](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf). -edit- Looked up the exact point in section J2 I wanted to refer to: … | |
Re: You can either implement your own classes to deal with it, although if building something serious (that requires performance) you're likely better off using an external library. A couple that come to mind: [TTMath](http://www.ttmath.org/) [GMP](http://gmplib.org/) | |
Re: It does it recursively. It goes down the correct path until it reaches the correct position. (at which point *leaf will be NULL) You seem to implement a binary search tree although you cannot insert the same value more than once. I do not know if this is desired but … | |
Re: I believe you made a topic about binary trees before and your case was a binary search tree right? (for everynode the condition holds that every node in it's left subtree is smaller than the node's value and every node in the right subtree is bigger or equal) You should … | |
Re: One thing to look out for is integer division. the return type of fact, x and n are all integers. Try this: #include<iostream> using namespace std; int fact (int no) { int total; for (int i=0; i<=no; i++) { if(i ==0) total = 1; else total = total * i; … | |
Re: This should work: #include <fstream> #include <iostream> #include <string> using namespace std; struct CALL_DATA { string list; int number; int lcmonth; int lcyear; }; int main() { int i = 0; CALL_DATA listd[100]; ifstream file ("list.txt"); if (file.is_open()) { while (file.good()) { char temp = 0; getline(file, listd[i].list); // The … | |
Re: How did you declare your function? The function/prototype should be defined as: void computeOrder(int& spoolOrderAmount, int& spoolStockAmount, double shippingHandling = 10.00); and the implementation as: void computeOrder(int& spoolOrderAmount, int& spoolStockAmount, double shippingHandling) { // code } | |
count.c:11: error: invalid operands to binary >> (have ‘double’ and ‘int’) Re: The result of "pow(2,31)" is a double. You apply a bitshift operation on it, which is not possible. Replace pow(2,31) with ((unsigned int)pow(2,31)) and it should work. You don't need pow to begin with though, you don't have to start from the most significant digit as you're just counting bits. … | |
Re: 1. You declare "census city[10];" within the loop while it's also declared outside of it.. 2. The issue is similar to your other thread. See my awnser there: http://www.daniweb.com/software-development/c/threads/437105/scanf-is-skipping-in-last-input-.-if-i-use-int-instead-of-charcode-is-runn 3. Use fgets() instead of gets(). Summary of the problem: With the first scanf a newline remains in the stream. gets() … | |
Re: Do you mean something like this: #include <iostream> using namespace std; int min (const int a, const int b); int max (const int a, const int b); int main() { int a, b, c; cout << "Enter three numbers: " << endl; cin >> a >> b >> c; cout … | |
Re: char *p1="Name"; // Non-const pointer pointing to non-const char. const char *p2="Name"; // Non-const pointer pointing to constant char. char const *p3="Name"; // Alternative syntax for p2. char *const p4="Name"; // Const pointer pointing to non-const char. const char *const p5="Name"; // Const pointer pointing to const char. ++p1; // … | |
Re: Hmm vague code is vague. I made a quick adjustment based on what i THINK you're trying to do here: #include <stdio.h> main() { char a[4][4]; int row,col; // Note that the body of this loop is executed only twice. // Is this what you want? for (row=0;row<4;row=row+2) { for … | |
Re: Try something like this: #include <stdio.h> #include <windows.h> const int DELAY_IN_MICROSECONDS = 100; int main (void) { char symbol = 'a'; while (1) { putchar(symbol++); if (symbol > 'z') { symbol = 'a'; putchar('\n'); } fflush(stdout); Sleep(DELAY_IN_MICROSECONDS); } return 0; } More information about Windows' Sleep function here: [MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx) | |
Re: What kind of keyboard hits? Do you want to detect any form of keypress? Does it have to happen while another activity is going on? Be more specific. It's likely (it depends on what you want exactly) that it's not possible in a platform independent way. Assuming you develop on … | |
Re: The code in itself is quite poor. In addition it's not clear to me what the program SHOULD do. Can you explain what the input is supposed to represent, when and which scores should be elinated and other relevant information? When entering the values you supplied the application outputs: > … | |
Re: A high "cool story bro" factor on this one.. You omit information and you do not provide any attempts done by yourself or even own thoughts on how to fix it. You could follow the primary-school like methods of multiplication e.g. 18 18 -- * 144 // 8*8 = 64. … | |
Re: You use some variables that aren't declared in the code. (e.g. mallocing with the size of "means" but later copying "mea" to that buffer. I will just assume this is correct, as I have no other choice) The essence of your problem is the following line: tmp2->meaning=tmp3; Once you've found … | |
Re: Hmm how do you brute force it currently? Some optimizations (but it's still brute forcing) would be to: - don't count the amount of digits per attempted number (or maybe not at all) instead start at i=10, j = 1 where you multiply i by 10 everytime your number hits … | |
Re: 1. You shouldn't really use gets(). 2. You're mixing scanf() and gets(). It's possible, but not recommended. Keep in mind that gets() looks for a newline (or eof) while scanf() tries to obtain the minimal and will keep the newline in the stream. (in this case) You could place a … | |
Re: Definately possible but quite challenging to find an optimal solution. Going to write down a quick first thought.. To make your example a little bit more complex say there's the following lines as well: StateNumber NextStateC 2 1 3 1 Given have the table filled already every branch of paths … | |
Re: Infix, prefix and postfix are merely notations. For example 1 + 2 : Infix, The '+' operator is written between the operands it applies to. 1 2 + : Postfix (Reverse Polish Notation), the '+' operator follows it's two operands. + 1 2 : Prefix (Polish Notation), the '+' operator … | |
Re: An easy approach would be to determine the mean in the first pass through the file, then go through the file again to determine the standard deviation by squaring the differences of every number with the mean and then take the square root of the average of those values. There … | |
Re: > So what doesn't work? You need to give us informations if you need help. > how can I do it reading from the file? It's clear what he wants to achieve. Going by his code sample it's also clear what isn't working. But I know you have a reading … | |
Re: "Multiple switch" case, I am not sure what you mean by this. Checking for multiple cases is what you'd typically use a switch for so yes, multiple "case" statements are allowed. Nesting a switch within a switch is also allowed. The switch body is just a normal or compound statement … | |
Re: There's multiple ways to do this. This could be solved with (discrete) math alone although I think you're aiming for a more brute-force approach right? In that case a logical start would be to implement the AdjBC() function. You don't have to start at the most significant bit for obvious … | |
Re: This assignment contains easy to identify subtasks which can be expressed in their own functions. Following this idea I would suggest something like the following: #include <stdio.h> #include <string.h> #include <ctype.h> #include <assert.h> // The maximum length of a string. #define STRING_MAX (40) // Function declarations/prototypes. void reverse_substring (char str[], … | |
Re: Start simpler. Create a function with the following signature: void repeat_character(const char symbol, const int amount) what it should do is it prints 'symbol' to stdout 'amount' times. So, print_character('2', 5); should print 22222 Once you have that solving your original problem should be easier. If you don't know how … | |
Re: I didn't really go over the code yet but how does it run for you when you change struct node *list1, *list2; to struct node *list1 = NULL, *list2 = NULL; ? | |
Re: Introducing a flag with additional code to set and check it seems like a poor solution, especially when it's not needed. Doesn't simply moving the printing instruction out of the loop do what you describe? main() { FILE *file = fopen ("COMMAND.txt", "r"); FILE *file1 = fopen ("LOG.log", "a"); if … | |
Re: While this doesn't even deserve an answer as you don't even ask a proper question (You just dump your code and state "it doesn't work!") you could try this. I'm not going to explain anything about it I guess as you didn't ask me to. It's also a naive implementation … | |
Hello Daniweb. [B]Scenario[/B] For a project we have to write a irc server. For this, we first wanted to investigate what kind of server architecture we should apply. (e.g. multithreading, multiplexing, multiprocessing etc.) We've written simple servers which implement different architectures. The servers basicially receive a message, and then send … | |
Hello Daniweb, I've ran against an issue in my code and i'm not sure why I receive an error. I've managed to reproduce the error with the following code: [CODE="C"] #ifdef _WIN32 #define PERFORMANCE_METING #endif #ifdef PERFORMANCE_METING #include <windows.h> #endif #include <stdio.h> #include <stdlib.h> typedef enum { FALSE, TRUE } … | |
Hello Daniweb community, Recently I bought a new harddrive. Below is a link to the manufacturer's website and the model: [url]http://www.seagate.com/ww/v/index.js...D&locale=en-US[/url] I connected the drive according to the instructions and then booted up my computer. The drive got detected in the BIOS so i booted up Windows. I then went … | |
Re: As far as I know Volatile is used when you don't want the compiler to perform certain optimizations with regards to value changes. (It is as if you say: "The value of this variable may change, even if this doesn't happen in the current program". This may happen in embedded … | |
Re: What you are doing now is trying to use a [URL=http://en.wikipedia.org/wiki/Function_object]functor[/URL]. (overloaded () operator for that object) Use the initialization section of the constructor to initilize the object: [CODE="C"] Desktop::Desktop() : otwarte_okna() { x1=y1=0; x2=y2=1000000; } [/CODE] | |
Re: eof becomes true when it has already read past the end of file. | |
Hello Daniweb, I'm trying to create a very simple shell for practicing purposes, but i'm a little bit puzzeled about the usage of execve, the function i use to execute a file. The code fragment underneath shows my usage: [CODE="C"] childPID = vfork(); if (childPID == 0) { execve(input.process, input.parameters, … | |
Re: Alternatively you could set your condition as the loop condition. A cunstruction I would use would be a do-while setup, as displayed below: [CODE="C"] int i; do {//return from the loop only when the input is zero printf("\n1: Stack1\n2: Stack2\n0: to return\n"); scanf("%d",&i); switch(i) { case 1: printf("1"); break; case … | |
Re: Your code seems to contain a lot of errors. You want to create a class called DayOfTheWeek that represents a day of the week. It looks like you have tried to store the actual data in a string object that you made private. That's an idea that could work. (The … | |
Re: I'm not sure if I understand your question correctly, but you could just copy the data like you would with non-allocated data. So something like this is what I mean: [CODE="C"] #include <stdlib.h> #include <stdio.h> #define AMOUNT_OF_DATA 20 int main (int argc, char *argv[]) { int *allocatedData = (int*) malloc(AMOUNT_OF_DATA … | |
Hello. I'm writing a program in C that should ask for a line of input, and extract the process name and parameters. This doesn't have to be totally bulletproof at this point. An example input could be: "Hello these are parameters". On this example "Hello" would be the string i … |
The End.