133 Posted Topics
Re: Maybe try [getaddrinfo(name, port, &hints, &result)](http://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx). There is an example at the bottom of the page. >pNodeName: A pointer to a NULL-terminated ANSI string that contains a host (node) name or a numeric host address string. For the Internet protocol, the numeric host address string is a dotted-decimal IPv4 address … | |
Re: Let's add more debug. Not making it into the for loop. **Code** #include <stdio.h> #include <stdlib.h> typedef struct IntNode { int data; struct IntNode *next; } IntNode; typedef struct List { IntNode *head; } List; IntNode *New_Node(int n); void Print_List(List *theList); void Free_List(List *theList); void Add_in_Order(List *list, IntNode *newnode); IntNode … | |
Re: Its taking a while to understand how you are doing it. So, I wrote it my way. The first thing I do see is that you are not swapping the min value with the head. http://en.wikipedia.org/wiki/Selection_sort 1. Find the minimum value in the list 2. `**Swap**` it with the value … | |
Re: I started to look at your issues but wound up rewritting the whole translateWord. Not what I wanted. So, I don't know if this will help, I will post the pseudocode. That way you can see some of the things I did to handle you issues. **Differentiate between y as … | |
Re: [quote=Moschops]Get a decent random number generator[/quote] I would have to be a uniformly distributed random number generator right? Or is that part of the simulation, normal vs. uniform? | |
Re: http://en.wikipedia.org/wiki/Circular_dependency Look at where it says Example of circular dependencies in C++. You need the class Map in Rabbit but Rabbit needs class Map. Hence circular dependency. Fix it with a forward declaration #ifndef RABBIT_H #define RABBIT_H // Remove the #include "Map.h" and use a // forward declaration class Map; … | |
Re: I took you code and made some small changes. Doing it this way fixes what you want to do. I tried to modify your code as little as possible #include <iostream> #include <fstream> using namespace std; class student { private: char grade; int calc; public: string first; string last; int … | |
Re: Lines 72, 94, 114, 156 and 187 all need more memory. Try char name[128]; // Or larger if you need it Now when you facanf or scanf into name you will have memory. See if that fixes it. | |
Re: Your number of sub-matrices isn't right. I think below is right but test it and test it some more. #include <iostream> #include <fstream> #include <sstream> #include <iterator> #include <vector> using namespace std; typedef vector<double> Matrix; // Had to pass input matrix size and output matrix size // Not using matRow … | |
Re: Not following what you want to do. What does swap them or create a new matrix mean? In formatMatrix the input is a 1D vector, so what happen to the matrix? Can you post an example with matrix1 and matrix2 input and what the output should be? | |
Re: When using char fname[MAXLEN]; you have to use strcpy or strncpy. http://linux.die.net/man/3/strncpy Like: strcpy(person.fname,fname); strcpy( personcpy.fname,person.fname); To use strcpy or strncpy add file #include <cstring> or you could use C++ strings and just use = to copy strings. http://www.cplusplus.com/reference/string/string/operator= | |
Re: This works. You have to wait for all started. #include <sys/types.h> #include <sys/wait.h> #include <cstdlib> #include <iostream> #include <unistd.h> using namespace std; int main(){ int pid,i,numOfProcess(10); for(i=0; i<numOfProcess; i++){ pid = fork(); // <-------- You had a == not = if(pid == -1){ // <-------- You didn't have a open … | |
Re: [code]#!/bin/sh read coursepath echo $coursepath | sed -ne 's/.*COSC[^0-9]*\(.*\)/\1/p' [/code] | |
Re: find / -name 'bash_profile' -exec cat {} \; Beware you might get more than one file | |
Re: If you want to use a \ in a string do two of them back to back like "user\\". Line 40 use 'g'. When you want a char you have to use ' not " which is for a string. | |
Re: Take a look at http://www.daniweb.com/software-development/c/threads/417121/calculating-powers-of-2, I got his program to calculate 2^50000 in 1.5 seconds. | |
Re: You can't use `if(ar[i] == ar[j])` because that is testing if the pointer values are equal not if the string are equal. You need to use `if ( strcmp(ar[i],ar[j]) == 0 )` to check if two strings are equal. If `strcmp` return 0 they are equal. Also there is an … | |
Re: Start the loop at 2 not 1. Right now its doing 8*8*-2 = -128. | |
Re: It is the mixing of the getline and operator>>. getline removes the '\n' if found but the last >> does not. So the first one works but the next getline reads the '\n' from the Newland data and then the >> tries to read the next line which is China … | |
Re: Maybe something like: #include <iostream> #include <string> int main(){ std::cout << std::string("No name").c_str() << std::endl; // Or std::cout << std::string("No name") << std::endl; return 0; } | |
Re: The code you posted didn't compile. test.c: In function ‘shuffle’: test.c:14: error: subscripted value is neither array nor pointer test.c:14: error: subscripted value is neither array nor pointer test.c:14: error: subscripted value is neither array nor pointer test.c:14: error: subscripted value is neither array nor pointer test.c:14: error: subscripted value … | |
Re: Try string streams: [code]#include <iostream> #include <iomanip> #include <sstream> using namespace std; string conv (int num, int base,int pad=0) { if (num == 0) return "0000000000000000"; char NUMS[] = "0123456789ABCDEF"; string result = ""; do { result.push_back (NUMS[num % base]); num /= base; } while (num != 0); stringstream strStrm; … | |
Re: Are you calling Delete with All = true or false? | |
Re: You were passing in number to the push function and setting the node->data to that value which was some random value coming off of the stack. Take a look at the changes I made, I put comments in to explain. [code]#include<stdio.h> #include<stdlib.h> #define p printf #define s scanf #include<ctype.h> struct … | |
Re: The main issue was that you defined a variable in main() called [B][COLOR="Red"]number_of_threads[/COLOR][/B] and a global variable [B][COLOR="Green"]number_of_threads[/COLOR][/B]. When you read in the value of number_of_threads it was to the local variable and not the global. So, when the threads read the value of the global number_of_threads it was ZERO. … | |
Re: After you pull all of the unique left side ID's, how many are there? And are they all 15 characters? How much memory do you have on your machine? | |
Re: How was the file that you are using for input created? It looks like you compressed then EncodeB64. | |
Re: Not sure what you want to do but this does something. I don't have windows so I removed and replaced some things. Many things going on here so take look and ask questions. [code]#include <iostream> //# define size 10; int mergesort(int,int); using namespace std; int main(int argc, char* argv[]) { … | |
Re: There is no problem with your code. You just need to wait for the output to come out. Or you could call [icode]fflush(stdout)[/icode] after the [icode]printf("Waiting for p2 and p3 to complete");[/icode] or put newlines (\n) at the end of your print statements. Other then that its working, it just … | |
Re: Line 22 should be [icode]for(i=16603;i>=0;i--)[/icode] because bin has 16604 elements. As for the speed up, you don't have to loop over all 16604 (in that same for loop) elements because the number of digits in the number 2^n is n*log10(2). Only go to the ceil(n*log10(2)) in the for loop. That … | |
Re: Can you use STL vectors? Edit: Never mind I just read the title. | |
Re: To block threads you might want to try [url]https://computing.llnl.gov/tutorials/pthreads/#ConditionVariables[/url] | |
Re: To get it right you need to pad the binary numbers out to 8 so when you group them by 6 you get the right answer [code]#include <iostream> #include <iomanip> #include <string> #include <sstream> using namespace std; #define Ord(c) ((int)(unsigned char)(c)) string DecToBin(int Num){ int Bin = 0, Pos = … | |
Re: You can do it all in the first for loop. All you need to do is save the start of a word in the array_str like [icode]array_str[j++] = &array_char[i];[/icode] and insert the '\0' as you are doing. Here is a way to get rid the '\n'. [code] #include<stdio.h> #include<string.h> int … | |
Re: Two things: 1. Take a look at what strtok is returning [code]./a.out love MONEY text.txt t.new.txt New file <t.new.txt> generated! [love] [is] [B][COLOR="Red"][patient love][/COLOR][/B] [is] [kind ] [/code] The first "love" matches because it matches. The second one doesn't match because it is "patient\nlove". 2. You can't copy the newwork … | |
Re: Here is a staring point. You started to use the inAWord but didn't take it all of the way. Think of it like in a word, not in a word, in a word, not in a word, etc... changing the value of inAWord as you go. Also there are some … | |
Re: Line 77, don't subtract 1. This is preventing you from printing out the last item. What would happen if you only had one item in the file? i would come out of the loop with the value of 1 and you would subtract 1 leaving size equal to ZERO. Then … | |
Re: numstore.size is a function, not a member. Add the () to get it to compile. And change /n to \n. [code] // Error if ((quartiles == 2) && (numstore.size / 2 == 0)) // Fixed if ((quartiles == 2) && (numstore.size() / 2 == 0)) [/code] | |
Re: Maybe something like this. [code]#include <stdio.h> #include <iostream> // # 3 #include <vector> #include "Fairy.h" #include "GoodFairy.h" #include "EvilFairy.h" #include "EquiFairy.h" using namespace std; // # 1 bool loadFairy(string infile,vector<Fairy *> &f){ bool ret(true); // Use ifstream to open and read data in infile // If file is open // … | |
Re: I think you could use sed or egrep. [code=shell]$ cat test.txt ----------- 50 (1 rows affected) $ sed -ne '/^[0-9]/p' test.txt 50 $ egrep "^[0-9]" test.txt 50 $ [/code] | |
Re: You are not allocating memory for the string value. Each time you add a node you are setting the string pointer to the same place and that place would be the memory of [icode]char word[50][/icode]. To fix you need to do a malloc of 50 bytes to [icode]n->string = (char … | |
Re: I got this from [url]http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file[/url] The problem you describe can be solved by defining the template in the header, or via the approach you describe above. I recommend reading points 35.12, 35.13, and 35.14 from the C++ FAQ Lite: [url]http://www.parashift.com/c++-faq-lite/templates.html[/url] | |
Re: Did you see this site? [url]http://www.songho.ca/dsp/convolution/convolution2d_example.html[/url] | |
Re: You could use Maclaurin series expansion for e^x = Sum(x^n/n!,0..N) were you pick N to give the you precision want. The power here is always an integer so that is just a for loop. And the factorial is just another loop. | |
Re: server.c [code] // Add read from client connection write(clientfd,message,c); int b[2]; while(read(clientfd,b,1) > 0){ /* Don't have the check here because the client closes the socket and that causes the return from the read to be -1 and while loop with exit */ printf("%c",b[0]); b[1] = '\0'; } printf("\n"); close(sockfd); … | |
Re: If I understand what you want, you have to loop thru the whole "packet" printing each hex byte. You want the output to look like that of the unix/linux command od: [code] 0000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00 0000010 … | |
Re: The link makes it clear. The code that you posted is not the code on the video. The code in video has this block of code [code]while(true){ int i = 0; while (i<80){ if(caRow[i]!=' ') { caRow[i]=GetChar(j+i*i,33,30); } std::cout << caRow[i]; i++; } j = (j+31); k = (k+17); l … | |
Re: Not sure what it is suppose to do, but what it does is for me after I got it to compile is repeat the same pattern every 1200 chars for infinity. The modulo function is correct. ((7+9)%30)+33 = 7+9+33 so it did what it should have. [code]cout << ::modulus(11,3) << … | |
Re: You need to have room for '\0'. Change [code] int EnORDe; char a,b; char newline='\n'; // <--- Changed, was getting a warning can't have two chars set to one char int pavalue[33]; // <--- 32 to 33 <--------------LOOK HERE //--------------- //reads passcode for value of array to use void passcode(int … | |
Re: Change line 208 to be [code] } while (passes <= 2 && slot->burst <= slot->working); /* line 208 */ [/code] Before this change, if burst was not a multiple of quantum you would be an infinite loop, as you did. |
The End.