1,494 Posted Topics
Re: try two for loops...one embedded into the other [CODE] for (i = 0; i < num; ++i) { for (j = 0; j < num2; ++j) {} } [/CODE] | |
Re: I think if you look closely, you'll find that your switch statement is outside your loop. This is your for loop [code] for (i = 0; i < 32; ++i) grade[i] = 0; [/code] To include the switch you'll need to add braces like [code] for (i = 0; i … | |
Re: Extended ascii characters are 8 bits, see link below [url]http://telecom.tbi.net/asc-ibm.html[/url] Try reading your characters into an unsigned char variable. | |
Re: Not really sure what your question is...well beside the main homework question.. | |
Re: So what you want is a function that creates a new string which is a copy of the string being past... Why not change the 'const std::string& a_string' parameter to 'std::string& a_string' and change original string or is that outside the requirements? Your question, get the iterators for the string's … | |
Re: Try looking at the code below..You should be able to finish it with this hint.. [code] #include <iostream> int main(int argc, char *argv[]) { int count_one = 1; int count_two = 10; for (int i = 0; i < 10; ++i) { for (int j = 0; j < count_one; … | |
Re: Try something like below [code] #include <stdio.h> #include <stdlib.h> unsigned long *lptr = NULL; int main() { lptr = (unsigned long*)malloc(sizeof(unsigned long)); /*check if allocation failed*/ __asm__ ( "movq %0, %%rax\n\t" "movq $6, (%%rax)\n\t" :"=m"(lptr) ); fprintf(stdout, "ans->%lu\n", *lptr); return 0; } [/code] | |
| |
Re: For this to work, you'll have to inspect each character from the stream using the isdigit() function. | |
Re: I literately typed this in google [quote] c++ number to string [/quote] and it returned itoa(). [url]http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/[/url] | |
Re: Could you be more specific? What do you mean by 'system'? | |
Re: The operating system will use the next lowest file descriptor for that application. It really makes sense if you think about it. Would you expect the operating system to return a random number? The third value is used if open creates a new file, its the umask value that's applied … | |
Re: Try adding to the top of your make file [code] all: list.o listinterface.o [/code] | |
Re: If the rows of data are consistent, why not create a structure to represent a row and have an array of structures. | |
Re: Your call to atoi may be failing. From my help file [quote] The atoi() function converts the initial portion of the string pointed to by nptr to int. The behavior is the same as strtol(nptr, (char **) NULL, 10); except that atoi() does not detect errors. [/quote] Try using strtol() … | |
Re: You were close... [code] #include<stdio.h> int main (void) { int row,col; int num; num=10; row=0; col=0; while(row<=num) { row++; while(col<row) { col++; printf("* "); } printf("\n"); col = 0; } return 0; } [/code] | |
Re: You can't create abstract objects, hence the term abstract. You can create a pointer to an abstract type but its must point to a derived object. Here's a simple coded example [code] #include <iostream> class expr_node//abstract { public: virtual ~expr_node() {} virtual std::ostream& print(std::ostream & out) const = 0; }; … | |
Re: The strcmp() function requires c-strings which must be terminated with '\0'. What your passing to strcmp() is a char pointer to one character. c-strings [code] char *str1 = "this is a c string";//compiler adds the '\0' char str2[] = "this is another c string";//again the compiler adds the '\0' char … | |
Re: Try this link [url]http://www.daniweb.com/software-development/cpp/threads/350132[/url] Didn't realize this was C++, replace std::cout with fputs(). | |
Re: [QUOTE=Buffalo101;1525061]Thanks for the reply, Dragon. Unfortunately, I think the problem is somewhere else. I've included the whole code here: [url]http://www.daniweb.com/software-development/cpp/threads/357691/1525051#post1525051[/url][/QUOTE] That code is C++, its not C. | |
Re: It could be this function [code] std::vector<passenger*>& passenger_queue::passengers_at_floor(int floor_) [/code] Try changing it to [code] std::vector<passenger*>& passenger_queue::passengers_at_floor(const int floor_) [/code] | |
How do you initialize a dynamic structure that has a const data member? I can provide an ugly hack but I'm at a loss as how to do it correctly. Actually, can you do this in a platform independent way? [code] #include <stdio.h> #include <stdlib.h> struct mys { const int … | |
Re: Try reading the last section of this page [url]http://pw1.netcom.com/~tjensen/ptr/ch8x.htm[/url] | |
Re: Your reading 100 digits, that's one big number. Its even bigger than an int. A safer conversion function would be strtol(), atoi() does not detect errors. | |
Re: Why not read 128 bits and mask out the unwanted data. | |
Re: In the second case, you can call the static function without an object. | |
Re: Did you allocated the memory? Try something like below. [code] #include <stdio.h> #include <stdlib.h> #define STR_SIZE 35/*don't use magic number use descriptive labels*/ #define ARR_SIZE 6 int main() { int i = 0; char *p[ARR_SIZE]; for (i = 0; i < ARR_SIZE; ++i) p[i] = (char*)malloc(STR_SIZE);/*allocate memory*/ for(i = 0; … | |
Re: Here's a simple server which receives a filename from a client, opens the file and writes the data to the client. If the file can't be found, it writes an error message to the client. From this bare shell, you should be able to create your simple web server. [code] … | |
Re: [code] uint16_t _inverse_logic:1; [/code] This creates a variable _inverse_logic which is one bit in size. | |
Re: I say this in the most constructive way, learn how to program in C and then learn how to program client/server applications and then learn the HTTP protocol. Line 8 is wrong. | |
Re: This will compile on both windows and Linux but you'll need the mingw32 compiler for windows and the GCC compiler for Linux. | |
Re: Its not about answers, its about guidance. Please post the code that you have completed so far. | |
Re: This should get ptr pointing at the first element of buffer. [code] unsigned short* ptr = (unsigned short*)buffer; [/code] Please note, when you increment ptr(or access an element with an index ptr[i]), the address increments by sizeof(unsigned short) and not by sizeof(unsigned char). | |
Re: Enumerated types are constant integrals, they are created by the compiler, so you can't convert a string to an enumerated type. Your enum [code] enum MyType{ Saw, Saw2, Saw3 }; [/code] the compiler would assign these values. Saw = 0, Saw2 = 1, Saw3 = 2 | |
Re: Why memory maps? Exe's, Dll's or shared objects need to be mapped into memory before they can be execute, you can't execute code from a drive it must be mapped into memory(RAM). Is it better? Depends, what are you reading and what are you doing with it. | |
Re: Well you could find out the hex value of 2584 and then place the appropriate values in the correct array elements or you could extend your array to five elements and create a c-string and use the function atoi() like below. [code] #include <stdio.h> #include <stdlib.h> int main() { char … | |
Re: I would look up the functionality of getline(). [url]http://www.cplusplus.com/reference/iostream/istream/getline/[/url] | |
Re: Read this [url]http://gcc.gnu.org/onlinedocs/cpp/Pragmas.html[/url] It pretty much explains it in the simplest terms | |
| |
Re: Right away, I would use array notation. [code] information = r_ptr[locationNumber].y; [/code] Your 2D array. Is that a pointer to pointer like [code] struct ruudud **r_ptr; [/code] or [code] struct ruudud r_ptr[4][4]; [/code] | |
Re: Try creating your function like so [code] void myfunction(int array1[][4], int array2[][4]) [/code] And calling it like so [code] myfunction(myarray1, myarray2); [/code] | |
Re: If your using bits then maybe you should consider a structure with bits fields. [code] struct my_bits { unsigned int one:1; unsigned int two:1; unsigned int three:1; unsigned int four:1; unsigned int five:1; unsigned int six:1; unsigned int seven:1; unsigned int eight:1; unsigned int nine:1; unsigned int ten:1; }; [/code] | |
Re: Line 5 in main, don't #include "quicksort.c". You should only include header files. | |
Re: When you pass a variable's address via a pointer, your just saying this is where I am. I hold the location of the variable in my value or I hold the value NULL. | |
Re: Well, you could post the code for starters. | |
Re: Your not guaranteed how the arguments in printf are evaluated, left to right, right to left..It depends on the C compiler your using!!!!!!!!!!!!!!!!!!!!!(many ! so the reply is urgent). | |
Re: I'm starting out with Qt4 and so far I'm impressed with the libraries and supporting tools/IDE like Qt Designer, Qt Creator, Kdevelop. | |
Re: You have a number of questionable things in that function. [code] float calcActualAmount(float amountP, int nrChildrenP) { float leftToSpend; if (calcAllowedPerChild(nrChildrenP) > 180) amountP = 180; else if (calcAllowedPerChild(nrChildrenP) < 180) leftToSpend = calcAllowedPerChild(nrChildrenP) - 100; do { for (int i = 1; i <= 5; i++) { switch (i) … | |
Re: When you have a pointer defined like so [code] char *ptr = "hello world"; [/code] It creates a read only character pointer. If you require a char array that's writable then use. [code] char ptr[] = "hello world"; [/code] |
The End.