1,288 Posted Topics
Re: http://www.cplusplus.com/doc/tutorial/files/ Halfway down: "Reading from a file can also be performed ..." | |
Re: Sounds like it doesn't know what kind of object Class_name is. Where did you tell it that Class_name is a type of a class? | |
Re: While I am not familiar with silverlight, I look at this code, and I see where you create the wstring object named `wsTransfer`, and then you make `wpszInput` point at that empty string, and then you set the text in `m_pColNum3` with that empty string. At which point is the … | |
Re: I would be remiss if I did not point you at this: https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful I would go so far as to say never use `rand()`, even in toy programs just for fun (because you might as well practice not using `rand()` to reduce the chance of ever using it accidentally). | |
Re: To iterate through a string is to conduct some operation on each char in turn. So get the string: `string value = "feeenhpoorilumayngtumseatsdmepotositnsfrlerruepsrennurdaorantiedbeunrtioradarahe";` and then go through every char in turn for (int i =0; i < value.length(); ++i) { char currentChar = value[i]; // do something with the char … | |
Re: You seem to have made this more complicated than it should be. In the following code, so long as the mutex named `mtx` is shared by all threads, each thread will wait to take the mutex, output `_printMe`, release the mutex. Each thread will output `_printMe` repeatedly; `repcout` times. There … | |
Re: See `Firstdata`? Whatever that is, you're defining it in list.cpp and again in main.cpp This is bad. Only define it in one file. | |
Re: The first time a is shown on screen is when you call the function `d.show_a();` The second time a is shown is when you call `d.display();` | |
Re: If you're going to write this in C++, which you clearly already are, don't use a char array to store the input. Use a C++ std::string, from the `<string>` header. | |
Re: #include <math.h> #include <cmath> `cmath` is the C++ header that is to be used in place of the C header `math.h`. So just use `cmath`. | |
Re: ` total += float read_input( a,b , c ,d,e );` Why does this line of code contain the word `float`? Also, inside the funciton `calculate_average`, the following variables do not exist; `a`, `b`, `c`, `d`, `e`. So you cannot use them in this function call. That's OK, though, because the … | |
Re: You can just ask your compiler. #include <iostream> #include <typeinfo> int main() { int a; long int b; float c; double d; std::cout << typeid(a + b - c * d).name() << std::endl; } | |
Re: Typically, -pthread would be one of your LIBS, but you don't seem to have one of those. I'd be tempted to add `LIBS = "-pthread"` at the top, and `${LIBS}` to the compile line. CC is your compiler. Somewhere, presumably, that's being set to gcc. You may have environment variables … | |
Re: > i am ask to create a program that will defined function that will do the same strcpy You haven't defined any functions. You're supposed to be defining a function that does the same as strcpy. Where is your function to do the same as strcpy? | |
Re: > I try to make program convert decimal to binary but, it adds the decimal number again. You put the decimal number in the stack, and then you put some other numbers on the stack, and then you output the entire stack. What's at the bottom of the stack? The … | |
Re: You're also using `printf` incorrectly. When you are printing out the value of an int, printf does not want the address of that int. It wants the int itself. `printf("%d", &rNumber);` is wrong. `printf("%d", rNumber);` is right. | |
Re: Looks like you're trying to execute the library file. That's not how programs work. You run an executable (the program you built that contains a `main` function) and that program calls functions from this library. | |
Re: If the numbers can range from 0000 to 9999, you can do it quite simply. Get string. Count number of letters. If not 4, bad. Use string function for this. Get first letter. Check it is a character from the set '0' to '9'. if not, bad. Use isdigit fucntion … | |
Re: You generate one random number and then you use that same number for your whole program. Is that what you meant to do? | |
Re: ` char x;` If you want the user to enter a string, shouldn't x be a string rather than a single `char`? ` my_str.find("x");` You appear to be searching for the letter x. Shouldn't you be searching for the string that the user entered? You also need to do something … | |
Re: If you pay attention to your code, when you set a pointer to NULL, when you come back to it later you can tell that you definitely meant for this pointer to not be pointing at anything right now, and you can make sure not to accidentally use it. That's … | |
Re: > when i put in 'c 50' it prints but keeps printing the same thing continously not stopping unless i close it. Your switch block: //process what user inputs switch (type) { is inside a `while` loop. Here's the start of the `while` loop: while (type != 'E') So this … | |
Re: Edit: Beaten to it by SRL. That'll teach me to type faster :) `Worker_name= worker1,worker2` `Worker_name` is an array of char. In this situation, it devolves to a char pointer. ` worker1,worker2` is basically nonsense in this situation. The `,` operator simply means that first the thing on the left … | |
Re: The code you have posted compiles fine (except that to use `system`, you should `#include <cstdlib>`). Whatever code you have that produces the error you mentioned is not this code. | |
Re: Building it with the following set of warning switches: `-Wall -Weffc++ -pedantic -pedantic-errors -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdisabled-optimization -Werror -Wfloat-equal -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Winline -Winvalid-pch -Wlong-long -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpadded -Wpointer-arith -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-aliasing=2 -Wswitch-default -Wswitch-enum -Wunreachable-code -Wunused -Wunused-parameter -Wvariadic-macros -Wwrite-strings` gives only … | |
Re: We can't guess what a function does. If we saw the code, we might be able to help you. ![]() | |
Re: You've mixed up `printf` and `cout`. cout doesn't do substitution of `%f`. That's a `printf` thing. With `cout` , you just state what you want output with a sequence of `<<` operators: `cout << "y = " << m << " x - " << b << endl;` | |
Re: Run it under a debugger. | |
Re: It's very ugly. #include <iostream> #include <cstdlib> using namespace std; class myclass { public: void class_function() { cout << "Class Function Called" << endl; } }; int main() { void(myclass::*myfunction)() = &myclass::class_function; // make function pointer to the class_function myclass cls; (&cls->*myfunction)(); // when using the function pointer, need to … | |
Re: What optimisation level are you building the code with? In both those loops, there is a significant amount of work that a good compiler will simply not bother doing. If you build it at the lowest level of optimisation, you might see a different result. What that invites you to … | |
Re: What are you compiling this with? The function binary is expecting an `int*` as the first parameter, but you're passing it an `int`. This is very bad news, and your compiler really should have said something about it. I see also that you're using unknown, basically random values for `a`, … | |
Re: > Bold Text Here Expression of incomprehension here. | |
Re: http://www.cplusplus.com/doc/tutorial/basic_io/ | |
Re: Here's the first error: `36:23: error: ‘strncpy’ was not declared in this scope` Now I've helped you find it, you can fix it. | |
Re: It's more typical to make this operator a friend, rather than a member function. We also need to see the definition. | |
Re: You're missing `;` after you declare functions at the top, you're using a `;` instead of a `,` in line 5 and 6, you're using `;` instead of `:` in some case statements. | |
Re: If all you have is a pointer, and it might be pointing to an element of an array, there is NO way to deduce the size of that array. Doesn't matter if it's 2D or 1D. If all you have is a pointer to an element in the array, you … | |
Re: `graphics.h` was a header file released with some compilers back in the eighties and early nineties (i.e. twenty years ago) that enabled a programmer to use a very custom library (also provided wit hthat compiler) to show simple graphics on the systems of the day. Are you programming for MSDOS … | |
Re: Your condition for accepting a number as part of your calculation is wrong. You are accepting it if: `it is a mulitple of three AND it is a multiple of two && it's not a multiple of eight` You've left out the check for having two or three digits, you've … | |
Re: First, the `break` statement on line 97 has no business being there, and the `{` on line 99 has no business being there. Secondly, your loop condition is fundamentally broken. `while (letter != 'Z' || letter != 'z');` The loop will continue as long as `letter != 'Z' || letter … | |
Re: If you look in the call stack, you will see the point at which *your* code calls scanf. The odds of there being a bug in scanf is tiny. The problem is almost certainly in how you are calling it, so when the crash happens, you need to look at … | |
Re: There is no one best. First, turn on lots of extra warnings/errors in GCC, and fix them all. `-Wall`,` -Wextra`, `-pedantic-errors`, and so on. Have a look through the list https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html Then, get the Clang/LLVM C compiler, and rebuild your code with that, similarly with lots of errors and warnings … | |
Re: Delete lines 4, 5, 6, and put this in place: while (n==1) { } Note that your code will loop forever if n is 1. This is almost certainly not what you want. | |
Re: You're supposed to be testing the two strings that the user entered, right? So shouldn't you be calling the mystery function AFTER the user has typed those string in? | |
Re: You see the `{` on line 16? It marks the beginning of your function `main`. Where is the `}` that marks *the end* of that function? (Hint; nowhere - you need to put it in). | |
Re: If you initialise a semaphore value to zero, it means that when you look at it, it will have the value zero. That's it. All the rest is interpretation. If you have decided that you want "zero" to mean "the data this semaphore is referring to is not being used, … | |
Re: I expect you're trying to output some kind of character with the value 1. This is an unprintable character and when your terminal gets told to output it, because it has nothing to show, it shows a little box with 0001 in it. You need to check what you're outputting … |
The End.