Click here to Skip to main content
15,354,816 members

Comments by k5054 (Top 200 by date)

k5054 24-Jun-22 23:40pm View
   
"i[s] doesn't even compile ... it's meaningless garbage."
Not true. In C and C++ 5[x] is perfectly valid, as is explained here:
https://stackoverflow.com/a/381549

I should add that except for lecture notes, trying it for yourself, obfuscated programming contests, and just someone being a right git, you should never see this usage in real life.
k5054 24-Jun-22 13:49pm View
   
If your PC and IPad are both connected to the same WiFi network, then any client/server TCP solution would work. Likewise, if the PC has bluetooth, then some sort of bluetooth transfer should be possible. Then there's USB, in which case you might have to treat the IPad as a storage device on the PC.
k5054 15-Jun-22 12:05pm View
   
I just tried this within VS, rather than compiling directly on the ubuntu WSL instance, and get the same behavior as you do in the "Linux Console Window" that VS gives you. But running the VS compiled executable on the Linux host (in this case a Pi, but assume its the same on an Ubuntu WSL instance), the executable performs as expected, I.E. a bare return works as expected. So it's something that VS is doing in the Console Window. Bleah. Presumably whatever that is is eating the CTL-C too. All I can suggest at the moment is to try running the program from an Ubuntu console, rather than the VS Linux Console Window.
k5054 2-Jun-22 12:38pm View
   
"Maybe lowering the priority needs permission too". Any user can reduce a processes nice value. The intent is that if you know you have a resource hog, you can make it "nice" and run at a lower scheduling priority. Important back in the days of single processors and limited RAM, etc. But you have to have root privileges to escalate a processes priority above the base of zero.
k5054 1-Jun-22 9:00am View
   
It looks like the remote scp command is trying to use password authentication. Are you sure you have the correct path for your /private/key/file, and that its the correct identity file for the remote host?
You could try turning off password authentication by adding -o PasswordAuthentication=false to your command line, You might also try adding -vv (yes, 2 v's) to get debug output to try to see why the remote scp is not working.
k5054 25-May-22 9:23am View
   
You've tagged this as C++, but it's clearly Java. Can you fix the tags? That might help getting help with your issue.
k5054 19-May-22 12:20pm View
   
Show us the parts that are causing you issues, and we'll try to help. We're not going to give you a full solution, thought.
k5054 12-May-22 11:14am View
   
Ah. Ok, so you're trying to do floating point math, whereas the shell only supports integer math. What you'll need to do is to use something like perl to do this, eg elapsed=$(perl -e "print $end_time - $start_time")
k5054 12-May-22 11:04am View
   
when using let, do not add spaces to the the statement. Use let var=a$-$b not let var=$a - $b
k5054 21-Apr-22 12:57pm View
   
I didn't look too closely at your code .. the problem is here
int main(){    new Admin[5];
While that does create an array of 5 new Admin objects on the stack, it does not associate it with any variable try instead
Admin *admins = new Admin[5];
// ...
     admins[1].setvalues(/* ... */); 
k5054 8-Apr-22 11:10am View
   
What is it you're trying to achieve? The packages to for SSL for PHP are probably available as standard RHEL rpms available through dnf. If you've got those installed and now need to know how to create an SSL certificate, there are two options available to you. If you do not need to have global access, you can google how to generate a "self signed certificate". These are fine for internal development, and/or internal services that only you or your company is going to use - you should be able to add security exceptions in your browser to accept the cert, even though it does not come from a recognized authority (e.g. Twate). If you do need to be accessible from the Web, then you need to get a cert from a recognized authority. You'll probably want to research Certificate Authorities, what the annual cost is, etc. Each authority will probably have a submission form for you to fill out to get your Cert.
k5054 2-Apr-22 10:52am View
   
I thought it worth while to explain why the compiler accepted the code. I'm sure we've all bumped into this from time to time. And will probably do so again. Fortunately, compiler warnings and debuggers make finding the brain-fades much easier these days!
k5054 1-Apr-22 13:06pm View
   
"the expression (pw,password) == 0 is invalid"
I think maybe you meant to say the expression is incorrect, not invalid, as it compiles just fine. If you turn on /Wall, the compiler will warn you that the expression before the comma has no effect. (Although that turns on a lot of other things you probably don't want, so use sparingly...)

The OP has inadvertently invoked the comma operator, see https://en.cppreference.com/w/cpp/language/operator_other#:~:text=function%20called%0A7.000000-,Built%2Din%20comma%20operator,-The%20comma%20operator
In brief (pw,password) == 0 evaluates pw (the address of the pw variable), throws that away, then evaluates password (the address of the passwword variable), and then uses that value as the left-hand-side of the comparison operation. Since password in on the stack, its address will never be zero (NULL), so the second comparison will always fail.
k5054 26-Mar-22 21:40pm View
   
Would it be correct to assume that you work with a buffer then tell the display that you have some data for it? In which case, if the [8x8]xn array for the display is contiguous, can't you just work with the 8x8 cells as a 8x8xn array and then inform the display that you've got data starting at location X of length n (or whatever it requires)?
Just trying to understand the problem ... since an int X[a][b][c] covers a*b*c*sizeof(int) bytes, its directly analogous to int X[a*b*c] If that works for you, you could venture into the dangerous world of type-punning or abuse of unions.
k5054 24-Mar-22 11:36am View
   
The OP has marked this question as C, not C++, so struct node is required. It is also the case that C does not require that assignments from void * be cast to the correct type, but it is still a good idea.
k5054 23-Mar-22 13:57pm View
   
dnf downloads and installs packages for you. All you need to do is as noted above
sudo dnf install libmcrypt-devel
That will download and install the latest libmcrypt-devel package (headers and probably a pkg-config profile). If you do not already have the latest libmcrypt package installed, that will be downloaded and installed or updated too. If libmcrypt or libmcyrpt-devel requres another package, for example say libImNeedtedToo, then it will be downloaded and installed for you too, as will anything libImNeededToo requires, and so on.
k5054 21-Mar-22 11:10am View
   
That sounds like a good way to allow a malicious user to grab root on your Pi, probably not something you want to do. In general anything that is user controlled and needs to have sudo root privileges to execute does not pass the "smell test", and would probably be banned by any competently run IT department. What you probably want to do is to re-think your startup procedure. Maybe do something with the pi users .bash_profile or .bashrc? Or modify the startup html document for chromium browser to use a value stored in a file (or database!) that a regular user does have access to without having to resort to sudo tomfoolery.
k5054 20-Mar-22 13:49pm View
   
Heh. Old Farts Brain Fart. Happens all the time :)
k5054 20-Mar-22 13:48pm View
   
See my reply to Richard, RE sudo nano. Another option would be to change the file owner to root andset the suid execute bit on the python script- if python scripts obey the suid permission settings. It's not clear why you'd want to do this from a script, unless you're writing a PI setup/configure script to have an automated way of producing PI's that perform some task, e.g. an info Kiosk, that you need to have several instances of.
k5054 20-Mar-22 13:43pm View
   
I think you meant just enter "sudo myscript.py" at the terminal. sudo nano will start the nano editor in sudo mode, at which point you'd need to do CTL-T to get a "command to execute" prompt, all of which seems a bit overly complicated.
k5054 17-Mar-22 22:23pm View
   
The compiler explorer (https://godbolt.org/) has no issues compiling your code. But I did need to add the /std:c++latest flag. I tested with X64 MSVC v19.29 VS 16.10 through X64 MSVC v19.latest. Maybe there's an issue with the 2022 Preview tools?
k5054 13-Mar-22 11:05am View
   
sudo su is a bit redundant. sudo runs the command line argument as another user - by default that is root, but you can specify other users with the -u flag. su does exactly the same thing. The difference being that sudo has finer grained controls over what users can execute which commands. If you need to get a shell as another user, you can use the -i or -s flags. So for example you could do sudo -u otheruser -i to get the equivalent of a login shell as otheruser.
k5054 11-Mar-22 15:21pm View
   
The ignore should happen just after reading in the single char for the confirmation response, not after the while statement. This is because if you do not answer si, you still need to remove the trailing newline before you call getline() at the top of the loop.
k5054 11-Mar-22 11:35am View
   
I would add a default: case to your switch block. Serial.parseInt() may not be returning what you think it is. In any case, it would be a good idea to let the user know when the input is invalid.
k5054 11-Mar-22 10:50am View
   
"how did you get the right solution?"
Experience, I suppose - although I'm quite capable of making this same error myself, even now - although I'd be much more likely to do another getline() rather than an ignore in this case, and then examine the first character to see if it matched, probably using tolower() so that case didn't matter.
k5054 6-Mar-22 16:50pm View
   
I assume you've googled for "C++ friend template class" and found this, which does not achieve what you want?
https://stackoverflow.com/a/8967610
k5054 23-Feb-22 18:11pm View
   
Two things:
1) You probably want to use float or double for your variables rather than int. Gravity near the earth is about 9.8 m/s^2, so a should be a floating point, at least.
2) The formula given gives you distance over time, To find the time the ball takes to drop from one floor to the next, you need to solve for t, which involves some algebra - I wish you luck.
k5054 22-Feb-22 13:59pm View
   
You have an erroneous value at the end of your list - eg 870780922 You'll have to take a look at your data file and see what's going on with it - otherwise your code works fine.
k5054 7-Feb-22 13:01pm View
   
Please add the actual error message that you are getting to your question. Otherwise, its impossible to know. Is the mysql server running? Is there a firewall issue? Are you trying to connect to the right port? Is your device and the PC on different network segments? Is networking on your device turned on? And probably many more possible issues.
k5054 6-Feb-22 17:39pm View
   
What compiler/OS are you using? Neither recent versions of GCC or MSVC give the error message you present here.
There is a possible typo in your Employee class, where the second constructor is spelled as Epmloyee
k5054 2-Feb-22 11:04am View
   
5'd. What a great mini-tutorial on how to go about finding and fixing syntax errors!
k5054 28-Jan-22 12:39pm View
   
But, but, but ...
you asked "How to select 2 values separated by a comma"! You need to give a exact example of your data! jsc42 has given you the right answer to the question you asked. So now you need to reframe the question. What, exactly, does your column data look like?
k5054 15-Jan-22 22:54pm View
   
I see no attempt at a linear search here. But unless you're required to write a linear search as part of your homework, then you should probably use the library standard lsearch() (or _lsearch() or _lsearch_s() depending on your compiler environment) routine.
k5054 9-Jan-22 11:15am View
   
Without some code to show us, we can't help. Are you calling the function correctly? Is the return value being used correctly or ignored? Does the function return a value for error and you're not checking?
k5054 5-Jan-22 13:11pm View
   
What compiler and options are you using to get that? I've tried with GCC and MSVC 19.30, both return an error about unrecognized literal suffix.

In any case int/int results in an int. In this case, 4/10 = 0, so multiplying by a double doesn't change things.
k5054 3-Jan-22 11:52am View
   
Every time you open a file with ios::out, the file is truncated. If you use the mode ios::app the file is opened in append mode - which appends written data to the end of the file. You may want to take a look at your Save_File function - it may not do what you think it does.
k5054 2-Jan-22 13:07pm View
   
Why? Assuming that you're using the free Turbo C++ 3.0, that goes back to 1992. There's better options available, unless you're stuck with a 1990's era computer and/or OS.
k5054 2-Jan-22 10:33am View
   
What compiler are you using? using namespace std; is absolutely correct for any implementation that supports C++-98 or later. Unless you're stuck on a DOS box, for some reason, then you should be using a new compiler. Visual studio is available as a free download (community edition), so you should consider that. There's also options for other compilers that could be used with eclipse or code-blocs or other free IDE's for windows.
k5054 30-Dec-21 23:07pm View
   
Presumably if you're using QString that means you're using QT. In which case, maybe you should use QProcess https://doc.qt.io/qt-5/qprocess.html
I'm not familiar with QT, but the web page says "The QProcess class is used to start external programs and to communicate with them", which sounds like its what you want.
k5054 30-Dec-21 11:30am View
   
While its not likely that a single input line is going to be over 10,000 chars long, you can guarantee that you won't end up with in the middle of some ginormously stupid input by using std::numeric_limits<std::streamsize>::max()
k5054 28-Dec-21 12:26pm View
   
+5 for inventiveness. Must be a slow day at work.
k5054 28-Dec-21 9:41am View
   
Thank you for your critique. Made my day.
k5054 28-Dec-21 5:22am View
   
"but it's not working" doesn't help much. What goes wrong? Does the program compile? If it does, what happens when you run it? Does it crash, or do you get unexpected results?
k5054 27-Dec-21 16:03pm View
   
And your question is?
k5054 26-Dec-21 17:17pm View
   
Without a base class to work from, how do you expect anyone to do anything?

Anything provided on the basis of this request is highly unlikely to integrate with any work that you've done. In addition, we have no knowledge of what topics you've covered in class. If we were to supply a template class using lambda expressions, for example, and those are topics you have not yet covered, your instructor might think that either you're a very advance student, or far more likely, guilty of plagiarism.

Maybe what you're trying to ask is how to derive a class from a base class? If so, see here: https://en.cppreference.com/w/cpp/language/derived_class If that page doesn't make much sense to you, then either that's way ahead of where you've got to in class or, more likely, you really need to speak with your Professor or Student Services and work out a way to get caught up.

Whatever you decide to do, it seems unlikely that you're going to be able to submit your assignment on time.
k5054 26-Dec-21 16:28pm View
   
Help we can do. Complete assignments we will not. I'm sorry you were in hospital. You should talk to your Professor and or student services. You'll not be alone in this. The school/uni you are attending probably has policies regarding prolonged absences due to health reasons - particularly at the moment with the pandemic.
But as to help, you'd need to show us your work, and give some details about what's happening (or not happening), with your code. But don't go dumping hundreds of lines of code on us. Try to break down the problems you're having into something small and concise.
If you can do Python, and understand Python objects, you've got a start. Start with creating a class for an employee, then derive an Hourly and Salaried employee from that. But you're going to have to do the heavy lifting. We'll help when you get stuck. But none of the regulars here will do your assignment for you
k5054 25-Dec-21 10:01am View
   
I've 5'd you, but I have to point out that the OP seems to have been given some function signatures to work with. Given that the requirement seems to be void EPF(double) and void CalculateBonus(double);, I'm not sure how to solve the problem without using global variables. Additionally the signature double DisplayTotalPay(double,double,double); seems particularly ridiculous, given that the purpose, extrapolated from the name of the function is to display something, there's no point in returning a value, and that other functions that should return a value don't. I wonder if the OP misstyped the assignment? If not, then I wonder about the qualifications of the instructor!
k5054 25-Dec-21 9:51am View
   
The algorithm library reduces much of this to single lines of code. But since you haven't started on it in class, then its probably best not to delve into it at this point.

If you look at other people's questions here about homework, the standard answer is "We don't do homework for you! You have to do it yourself. But, we will try to help you understand why your code doesn't work".

You've got some code here. That puts you ahead of many who post for homework help. But all we know at this point is that you have some sort of issue with it. You haven't said what that issue is. Does it fail to compile? Does it produce the wrong output? If so what's wrong with the output? Are you having an issue grasping the concept, or in this case a stage of the algorithm provided, and can't quite see how to proceed? What, exactly do you want assistance with?
k5054 25-Dec-21 9:27am View
   
And your question is?
Also, have you been introduced to the algorithm library yet? Much of the work for this exercise can be achieved with functions found there.
k5054 23-Dec-21 7:24am View
   
Yeah, you will. They sneak up on you!
k5054 23-Dec-21 7:05am View
   
I think the OP must some have other problem that he should examine. C++ will add a return 0 if no other return value from main is specified. If the OP's code is returning some other value, and main() does not have a return statement, then something is wrong. Unfortunately, the OP's code does not compile, even allowing for missing #includes. There are various variables that are accessed but not defined, and there's no closing brace for main(), so there's no knowing what the code might be doing in the missing sections.
k5054 22-Dec-21 21:16pm View
   
Your expected results got lost somewhere. Please update your question.
k5054 22-Dec-21 18:48pm View
   
You should probably investigate how to use the debugger. It will help you understand why either your compress or decompress routines are failing. I have not looked into your code too deeply, but an "off by one" error is a common mistake, even for experienced programmers!

In the previous reply, I should have pointed out that you might need to add 1 to the amount of memory you malloc() to allow for a NUL ('\0') byte at the end of the string. Not allowing for the fact that C strings have a NUL terminating char is one of the many sources of the 'off by one' bug.
k5054 22-Dec-21 18:42pm View
   
malloc and free are essential tools for the C programmer. You should google for some malloc tutorials if you don't know about them, yet.
Basically malloc returns a block of memory, suitably aligned for the storeage of any data. so a call to malloc(1024), returns a pointer to a block of memory of 1024 bytes. In your case you would do
char *Message = (char *)alloc(count);
and then later call free(Message)
I'm not sure why you think you need to multiply count by sizeof(long). count is the size of the file, so you don't need to multiply anything here.
In C, you don't need to cast the return value of malloc to the type of the object you are assigning it to. Whether you do or not is a matter of style, and/or coding standards. For C++ a cast is required, but for C++ you should use one of the C++ cast operators.
k5054 14-Dec-21 12:43pm View
   
Quote:My PC is almost too fast for this Some possible work arounds would be to get a pi-zero and peg its max CPU freq to 700MHZ ( = min). That's still probably way faster than your IoT device, but it might be slow enough to evaluate code speed. Alternatively, maybe a Qemu, or other emulator, would suffice. Emulating is generally slow, so might be able to assist. With an emulator, even if you're emulating a Pi, you can probably limit the amount of RAM so you can get some idea how things are affected in that area too.
As to a hash tables, have you looked at hcreate/hsearch/hdestory? The big downside to those is that there can only be one hash table at a time, but there is a GNU extension hcreate_r() etc. that allows you to specify a search table. You could, of course, look a the code in gnu-libc, but then you get LGPL issues, which might be a deal breaker.
k5054 10-Dec-21 23:26pm View
   
Its late and I goofed on typing the text. Ten lashes with a wet noodle for me, but it was enough to get you over the hump, I hope.
k5054 10-Dec-21 18:03pm View
   
Unless you've got a good reason not to, you should probably stick with strlen(), rather than writing your own - especially if you're dealing with long strings. Your system supplied strlen will probably make use of assembler instructions that will greatly improve performance. For example, on my home PC calling your get_string_length_from_pointer() on a 5MB string takes about 60 times as long as calling the system provided strlen(). That's without any optimization, but even turning on full optimization, strlen() still outperforms by a factor of about 9:1. The same will be true of other string functions in the string library.
k5054 8-Dec-21 11:33am View
   
Have you read (and understood) this: Template Instantiation (Using the GNU Compiler Collection (GCC))[^] I'm wondering if extern templates do what you need. If you are using G++-8 or earlier, there's also a -frepo option that might help. You could drill down from here GCC online documentation- GNU Project[^] to get to the closest G++ version to what you're using. All this supposes that the g++ provided by the device manufacturer has not omitted this from their toolchain.
k5054 7-Dec-21 17:37pm View
   
Oops, you're right (there probably should be, though hint hint). I guess I meant Voltage::get_Vout()
k5054 7-Dec-21 17:18pm View
   
I'll give you a clue to help with the debuging: If you put a break point at Voltage::voltage_divider_Calc(), what are the values of the voltage member variabes _R1, _R2, and _Vs? Why?
k5054 7-Dec-21 7:31am View
   
5ed. I wish I could give you more ;).
k5054 6-Dec-21 17:32pm View
   
Further reading the Common Function Attributes (Using the GNU Compiler Collection (GCC))[^] suggests that maybe the attribue "flatten" might get you closer to what you want. From the docs: Quote:flatten
Generally, inlining into a function is limited. For a function marked with this attribute, every call inside this function is inlined, if possible. Functions declared with attribute noinline and similar are not inlined. Whether the function itself is considered for inlining depends on its size and the current inlining parameters.

I read that as the flatten attribute applies to all function calls within the annotated function, not the function itself. So perhaps a combination of flatten for the caller and always_inlinefor the called functions gets you there. Or at least closer.
k5054 6-Dec-21 10:31am View
   
Because String hey = "Hello" is NOT an assignment. The compiler treats this as construction with an initial value. I.E. the compiler treats this as String hey{"Hello"}. Perhaps if you were to construct, then assign a non-array String using your original code, you would also get an error.
k5054 5-Dec-21 12:10pm View
   
What happens when you try to run the program? Does it crash? Does it print the wrong value? Does it print anything? Please let us know what issue you have and we might be able to help you resolve them.
k5054 5-Dec-21 11:41am View
   
You will need to provide the code for the String class, otherwise we cannot know. There might be anything in there that's messing up the array assignment. Does you assignment operator work for non array instances? As you know from your earlier question the code String a = "hello" does not call the operator=() method, but a constructor. So prove to yourself, at least, that assignment works for your String class. If basic assignment works, then come back here and post the code for your String class and maybe we can help you.
k5054 18-Nov-21 11:11am View
   
I was surprised at how many web resources make the same mistake. It took checking several links to find a correct one. That being said, I guess it should be pointed out that given modern hardware, the likelihood of realloc failing is quite small, particularly in a small program in 64-bit mode where your virtual memory is on the order of 256TB. But that doesn't excuse sloppy programming!
k5054 18-Nov-21 9:41am View
   
Except don't use that example, as it has a bug. In particular, if realloc() can't allocate new memory, it returns NULL, and does not change the contents of what was pointed to. So in the expression ptr = realloc(ptr, newsize), if no memory is available, then ptr gets set to NULL, and you've lost the handle to the memory you have allocated. Take a look at https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/realloc.php instead
k5054 25-Oct-21 22:46pm View
   
Addendum: Sometimes I think the Universe likes synchronicity. Posted earlier in Insider News : https://www.codeproject.com/Messages/5839439/Cplusplus-Smart-pointers-and-arrays
k5054 25-Oct-21 16:04pm View
   
Unless, of course the OP is using plain C rather than C++. In that case there's a whole lot of understanding to make sure that the non tread-safe function behaves correctly. It probably involves mutexes and/or condition variables to control access to the non-thread safe sections of the g() --- assuming the OP has access to g() and permission to modify the source.
k5054 21-Oct-21 21:05pm View
   
Have you considered std::any as your key value? That might work, but you might then have to box/unbox the values. If you do need to box/unbox, it might be better to create an ADT with a hash() member function - or perhaps even a template class.
k5054 19-Oct-21 18:15pm View
   
Checking gcc-11 and clang at the compiler explorer (https://godbolt.org/), the small string optimizations don't come into play - even at -O3 both compilers make a call to std::string.compare(). Just FYI.
k5054 14-Oct-21 11:28am View
   
What are the specs on the PC? Specifically what motherboard? Ubutuntu 16.04 was released in 2016, and went EOL in April of last year, so almost all PC's manufactured in that era should be supported. How are you installing? From DVD or USB stick? Can you boot a live DVD and see the SATA controller? e.g lspci | grep SATA should show list the controller. Once you know the SATA controller model, maybe a google search for that Ubuntu 16.04 might give useful results.
k5054 8-Oct-21 17:09pm View
   
You should probably use the "Have a question or comment" button below a solution to, rather than starting a new solution, if you have further questions about it. When you do that the person proposing the solution should get notification about it and know to respond. Otherwise they might not know that further information is needed.

If you only compile main.cpp, then you'll never get the code from human_function.cpp added to the program. As both Rick York and I have noted in Solution 3, it's not the right thing to do to #include "human_function.cpp" in human.h. If you want to compile in a single step, then use
g++ -Wall -Wextra -g main.cpp human_function.cpp -o main
this compiles and links in a single command line.
Does that answer your question?
k5054 8-Oct-21 16:48pm View
   
Further to what Rick has said, lets imagine you've implemented a stack, with the class header stack.h, and the implementation details in stack_impl.cpp. Now, if you have a program made up of 3 separate files, say main.cpp, automobile_stacks.cpp and aircraft_stacks.cpp, all of which include stack.h. With your solution, each compilation module will include a copy of the source code from stacks.cpp, and compile a copy of the code. This means that each object file (.o) will contain a definition of stack::push(), stack::pop() etc. Now when you try to link the 3 object files together the linker won't know which version of stack::push to link with, and will produce error listing complaining of multiple definitions of stack::push.
k5054 24-Sep-21 15:19pm View
   
What system are you getting the message "No child processes" on? The RPi or your PC? Perhaps add a call to strerror() to add to the error message so you know why your open() is failing.
k5054 20-Sep-21 10:52am View
   
Please post the linker error.
k5054 17-Sep-21 15:37pm View
   
It looks like std::uniform_int_distribution produces different results on windows and linux. Windows and linux both produce the same output for the following program:
#include<iostream>
#include<random>

int main()
{
    std::mt19937 rnd(1);

    for(int i = 0; i < 10; ++i)
        std::cout << rnd() << '\n';

}
I get the same results, namely:
1791095845
4282876139
3093770124
4005303368
491263
550290313
1298508491
4290846341
630311759
1013994432
Modifying the program to
#include<iostream>
#include<random>
#include <cstdint>

int main()
{
    std::mt19937 gen(1);
    std::uniform_int_distribution<int64_t> rnd(0, 100);

    for(int i = 0; i < 10; ++i)
        std::cout << "rand = " << rnd(gen) << '\n';

}
I get the following:
Linux   Windows
  42      23
  100     25
  72      37
  94      100
  0       100
  12      95
  30      72
  100     14
  14      49
  23      84
Unless I've done something wrong, here.
k5054 29-Jul-21 13:51pm View
   
Error code C2065 refers to an undeclared identifier. Have you declared and initialized s?
k5054 26-Jul-21 9:33am View
   
Your Listclass compiles fine. Your main function is incomplete. This suggests that the error you are seeing is within main<code>. As Richard has said, please fill in the details.
k5054 2-Jul-21 14:39pm View
   
Playing around with compiler explorer https://godbolt.org/ it turns out gcc, clang and MSVC are all capable of optimizing away the strlen call. Even better, as near as I can tell, MSVC manages to inline the strlen call.
k5054 2-Jul-21 14:20pm View
   
One probably shouldn't call strlen() for each character placed in the result. If one or two or both are long, think several MB, then the performance of this will probably be very poor --- assuming the compiler isn't able to optimize away the strlen calls. Better to create a const int and assign the return value of strlen to it for len_one and len_two, then use those tokens in place of the strlen() calls. You could also do a little math ahead of time and only use the for loop to the min(len_one, len_two), and then use strcat to copy the rest of the other string. I'll leave the actual implementation to the OP, if they're inclined
k5054 27-Jun-21 13:46pm View
   
Quote:it is always a bad idea to use void pointers because the compiler wont help you anymore. True enough, but sometimes with C, there's no other option. C does not have any concept of generics, so resorting to a void* is the best a C programmer can do. Even the standard library needs to rely on this for functions like qsort() and bsearc().
k5054 27-Jun-21 13:37pm View
   
Is some of your code missing? You say "it does not mark any error either", which I take to mean your code compiles cleanly, but the given code does not. In particular there is no declaration of variables i, x, N in scope for functions Columna and Renglon.
k5054 19-Jun-21 14:10pm View
   
Your script does not "go" anywhere. Maybe you mean you need to do the equivalent of
echo `echo system > /sys/firmware/zynqmp/shutdown_scope`
. If so, there a 2 options. Either use the system() call, or open,write,close the file programatically e.g.
// use system
system("echo system > /sys/firmware/zynqmp/shutdown_scope");

// open, write, close FILE
FILE *scope = fopen("/sys/firmware/zynqmp/shutdown_scope", "w");
fprintf(scope, "system\n");
fclose(scope);
Note that I have not done any error checking, so that should probably be something you should consider. If the system() call might produce an error or other feedback, take a look a pope().
k5054 15-Jun-21 15:16pm View
   
the statement std::list<unsigned short>* myList; declares the variable myList but it does not initialize it. Assume, for the purposes of discussion, that the compiler gives myList the value NULL when declared, unless assigned at declaration time. What you have then is the equivalent of
 (NULL)->push_back(val)
. You need to assign a value to myList, either through new (or a smart pointer), or by assigning the pointer to an already existing list of a conforming type. Just declaring a pointer variable, and then trying to use it without pointing at something first is a programming error.
k5054 24-May-21 18:20pm View
   
If you're not seeing anything in wireshark, that suggest that the problem might be on the other end. Do you know its completed the read successfully on the opposite side, and has send back the confirmation?
k5054 19-May-21 15:09pm View
   
When you have
char *s = "Hello"
the string compiler effectively uses
char *s = (char []){ 'H', 'e', 'l', 'l', 'o', '\0'}
Writing the string in quotation marks is really just a shorthand for the fully decorated array of characters. Knowing that, you can, if you so desire, declare a int pointer (or double, float, etc) exactly the same way, e.g.
int *x = (int []){ 0, 1, 2, 3 };
k5054 15-May-21 17:46pm View
   
That's a pointer declaration.
k5054 15-May-21 10:00am View
   
Take a look at functionThreee. The parameter passed in as delta is a double. The for loop uses a integer index i, but then adds the double delta to i. Since i is an integer, it can only have the values 0, ±1, ±2, ±3 etc, then adding an delta < 1.0 does not change the value of i.
k5054 12-May-21 16:59pm View
   
I guess it's all what you're used to. I've been doing K&R style since before the days of ANSI C standard. Like many, I learned C programming from their book. While I use the "hanging brace" style for inner control blocks, I have a strong aversion to hanging braces on the same line as the function definition. That's just wrong. There's a wikipedia page about indentation styles, for the interested: Indentation style - Wikipedia[^]
k5054 12-May-21 14:30pm View
   
To be fair, K&R also puts braces on the same line as an if, while, for, etc. but on a separate line for functions. And so does Stroustrup, so I think the OP is in good company with his brace style
k5054 2-May-21 12:24pm View
   
Also, you have a ORDER BY CLEARING_CYCLE that appears in the query, but not in either of the tables, nor as an alias to a column in the query. Please clarify.
k5054 2-May-21 12:01pm View
   
It would appear that IMG_PDC_OUTWARDCLEARING is "Table 1" in your data example, but I don't see where "Table 2" makes an appearance in your Query. Perhaps you could add actual table names to your data sample to help clear things up a bit?
k5054 1-May-21 13:10pm View
   
Perhaps this is a translation issue from OP or Consultants native language. Maybe a callback function is what the OP is after: https://en.wikipedia.org/wiki/Callback_(computer_programming)
k5054 1-May-21 12:06pm View
   
Or better yet, give a (short!) example.
k5054 1-May-21 12:03pm View
   
Lets try this again: I think this has to do with how scanf handles whitespace, in that given a format string "%d %d", scanf will consume any and all whitespace between integer values. So if your format string ends with whitespace, (tab, space, newline, etc), then scanf will try to consume all trailing newlines to satisfy the format string. The only way to proceed, then, is to enter a non whitespace character.
k5054 1-May-21 11:56am View
   
Deleted
I think it has to do with how scanf() handles white space. e.g.
you get the values 7 and 24 printed out, regardless of how much white-space (including new lines) you have in the buffer. So if your format string for scanf ends in any white space, then what scanf is doing is continually trying to consume the ending whitespace to satisfy the format string, which means that you can only proceed to the next input value by entering a non-whitespace character.  So using my example code above, if you enter "10
a" (or even "10a"), then scanf can proceed (or as in this case, terminate) when it finds the ''
k5054 1-May-21 11:11am View
   
Interesting. I've hit enter about 10 times after entering a number, and gdb says I'm still in scanf. eg:
[k5054@localhost]$ cat example.c
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    printf("enter a number: ");
    scanf("%d\n", &n);
    printf("n = %d\n", n);

    return 0;
}
[k5054@localhost]$ gcc example.c -o example
[k5054@localhost]$ ./example.c
bash: ./example.c: Permission denied
[k5054@localhost]$ ./example
enter a number: 10





^C
[k5054@localhost]$ gdb example
GNU gdb (GDB) Fedora 10.1-4.fc33
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from example...
(No debugging symbols found in example)
(gdb) r
Starting program: /home/ebacon/tmp/example 
enter a number: 10



^C
Program received signal SIGINT, Interrupt.
0x00007ffff7ec4442 in __GI___libc_read (fd=0, buf=0x4056b0, nbytes=1024) at ../sysdeps/unix/sysv/linux/read.c:26
26        return SYSCALL_CANCEL (read, fd, buf, nbytes);
(gdb) bt
#0  0x00007ffff7ec4442 in __GI___libc_read (fd=0, buf=0x4056b0, nbytes=1024) at ../sysdeps/unix/sysv/linux/read.c:26
#1  0x00007ffff7e55122 in _IO_new_file_underflow (fp=0x7ffff7f96800 <_IO_2_1_stdin_>) at libioP.h:948
#2  0x00007ffff7e563a6 in __GI__IO_default_uflow (fp=0x7ffff7f96800 <_IO_2_1_stdin_>) at libioP.h:948
#3  0x00007ffff7e2ed5b in __vfscanf_internal (s=<optimized out>, format=<optimized out>, argptr=argptr@entry=0x7fffffffd930, 
    mode_flags=mode_flags@entry=2) at vfscanf-internal.c:3023
#4  0x00007ffff7e2c712 in __isoc99_scanf (format=<optimized out>) at isoc99_scanf.c:30
#5  0x0000000000401163 in main ()
(gdb) quit
A debugging session is active.

        Inferior 1 [process 195134] will be killed.

Quit anyway? (y or n) y
[k5054@localhost]$ 
[k5054@localhost]$ lsb_release -ir
Distributor ID: Fedora
Release:        33
[k5054@localhost]$ 
k5054 1-May-21 10:21am View
   
Did you try this? For me, this just hangs in scanf.
k5054 29-Apr-21 13:01pm View
   
You need to call initscr() to initialize ncurses. Once you've done that getch() should work. But then you really should use the curses output routines to draw your playing surface, move the ball and move the paddles. Don't forget that cout is buffered, so it doesn't send output to the screen until either you write a newline ('\n') or use std::endl. In either case, a newline is sent to the screen, which could result in the screen rolling up. If you insist on using stdout, then you should probably use std::flush, instead, which sends output to the screen without adding a newline.
k5054 27-Apr-21 22:21pm View
   
I'm not sure why you're getting the error in songs.ccp at line 60, since it compiles fine for me, but the warning type qualifiers ignored on function return type is because you have const boolshowAll(). The compiler is telling you that the const qualifier for those functions is being ignored. An integer type is returned as a value, so is in a sense always const as you can't reach into the function and alter the value. The caller of the function gets a copy of the value, and is free to do what it will -- either compare against another value, or store it for later use. So if I had
const int f();
/* ... */
int x = f();
I have assigned the copy of the value returned from f() into variable x, and can now modify x as I please, and it can't affect the return value from f(). If I need x to be unmodified, I have to specify that on the caller side e.g. const int x = f().
k5054 27-Apr-21 17:45pm View
   
Hmm.. Maybe we need to define terms. I've always called () brackets, {} braces and [] square brackets. With that in mind, lets rewrite the code, as pasted, with a slightly different format:
ball->changeDirection(
                         (
                              edir
                         )
                         (
                             (
                                 rand() %3
                             ) +4
                         );
Clearly, there's a missing closing bracket ) for the call to changeDirection.
k5054 10-Apr-21 14:10pm View
   
C++ is a superset of C (mostly), so if you're happiest writing C style code, but compiling with C++, then do so - especially if its just for your own amusement/consumption. In a work related situation, you would probably be expected to follow company guidelines and coding conventions, but that's a different kettle of fish.
I think that there's boilerplate around here that says anything posted here is considered in the Public Domain. Even if its not, the code I posted here is pretty generic. I would expect any more-or-less experienced programmer to come up with something almost identical. And, in any case, this site is supposed to be about sharing ideas, so copy away!
k5054 10-Apr-21 12:39pm View
   
Seeing as you've tagged the question with C++, and used cout in your program, I hope I can be forgiven for assuming you were looking for C++ code :)

I don't actually do a lot of C++ myself - I learned C back when K&R was about the only reference there was. This was in the days of pre ANSI C so we didn't even have function prototypes, or void*. So most of my C++ tends to be C + STL, which is just fine, I think. ISTR that Stroustrup has said that C++ is a multi-paradigm language, and any way you want to use it, that's fine by him.

That being said, if you are going to be using the C++ compiler, you might as well add some of C++ goodness, like vectors and maps, ranged for loops, auto type deduction, etc. If nothing else, I think it produces somewhat easier to read code, and by pulling in the STL you've got a huge bag of tricks, written by really smart people, to rely on.
k5054 2-Mar-21 17:51pm View
   
What's in #include "TDU attamp_t.h"? If I comment that out, remove using namepace std and properly specify cin, cout, pair, etc as being in namespace std, it compiles fine.
k5054 22-Feb-21 17:33pm View
   
True, but what's the reverse of 1000? Using integer math you'd get back "1", which isn't really correct. If only there was a way to convert a number to a string, and reverse the string.
k5054 17-Feb-21 12:17pm View
   
Maybe you could explain a bit more about what you are trying to get at the end of this? For example given the following directory structure:
/home/TestC1/
|-- able/
|-- baker/
|   |-- alpha/
|   |-- beta/
|   `-- gamma/
`-- charlie/
What should the output be? Did you want just the last path element, the whole thing, anything after the base (/home/TestC1 in this case), or ???
k5054 16-Feb-21 13:00pm View
   
There is also a copy of the Window object created in the call to Room::AddWindow(). So by the object that vector::push_back() adds to the vector is a copy of the copy.
k5054 12-Feb-21 12:18pm View
   
You're welcome! Glad to be of assistance
k5054 10-Feb-21 11:04am View
   
Have you looked at the packet contents? Wireshark https://www.wireshark.org/ is my tool of choice. It should be available as an APT or DNF/YUM package if you are using linux, and is available for download for windows from their site. At least then you would know if your ISP is injecting something (naughty, naughty!), or if its a buffer overflow/reuse issue.
k5054 9-Feb-21 13:18pm View
   
Did you read everything I wrote? I suggested using
#pragma once
rather than include guards. I don't see where in your issue description you say you have a problem with that suggestion.
k5054 20-Jan-21 13:19pm View
   
You'll need to give us some more information, please. What OS and what SQL database engine are you using? Take a look at your database documentation, many databases now can produce JSON output, rather than a text table or CSV values.
k5054 17-Jan-21 16:02pm View
   
You only need to set SO_REUSEADDR on the listening socket. Even without SO_REUSEADDR, the port will become available again, after some amount of time. I think that's usually 3-5 minutes. If you're on Linux you can use
netstat -t
to show network connection status. A connection with status TIME_WAIT is a connection that has closed and is in the "timeout" section of the connection tear-down. Unless SO_REUSEADDR has been used on the connection, no new connections can be established on that port until the TIME_WAIT status has elapsed. See the man page for netstat for more useful information about network connections available from the command line
k5054 14-Jan-21 20:40pm View
   
Have you considered using rsyslog to send the logs to a central server. That way you would not have to visit various hosts to get the logs. Googling for "linux syslog remote servier" should get you various hits.
k5054 11-Jan-21 15:57pm View
   
In what way does this not work?
Why "Do not modify below this line" ??
I think it would be helpful if you did something like:
int maxIndex = lastMax(n, x);
printf("Max value: x[%d] = %d\n", maxIndex, x[maxIndex]);

But you should probably test that maxIndex is not -1 first.
k5054 10-Jan-21 13:41pm View
   
I think that should be
#include "../include/Calculator.hpp"
, for linux.
k5054 7-Jan-21 10:36am View
   
I could, but I think you would get more out of it if you tried to solve it yourself. Take a look at documentation for string ops (strcpy, strcmp, etc), and give it a try! If you still have problems, post another question.
k5054 19-Nov-20 18:02pm View
   
No, but it looks a lot simpler than mucking about with gmp. But there's a boost multi-precision class that might be a better option. One of the types wraps gmp bigints so you get a cleaner interface and trusted goodness of gmp and boost.
k5054 19-Nov-20 17:49pm View
   
k5054 13-Nov-20 9:32am View
   
works for me too ... Maybe the op actually has '\' followed by 't' to replace, rather than tabs?
k5054 13-Nov-20 9:21am View
   
Not sure why you would use cat when sed knows how to read from a file
sed -e 's/\t//g' sourcefile > destfile

You could also do this in place:
sed -i -e 's/\t//g' sourcefile
k5054 10-Nov-20 16:14pm View
   
It's probably the one that should go after the getch() :)
k5054 25-Aug-20 16:39pm View
   
note that you're columns/rows are backwards: If you ask for 5 rows and 3 columns, you actually print out 3 rows of 5 columns each.
k5054 13-Aug-20 15:49pm View
   
Are you spawning a new thread or process when a device connects to the REST server? If you are not, look into how you might do that for your platform. If you are, then take a look at what you are doing between getting a connection and spawning the trhead/process.
Alternatively, look at spawning several processes when the REST server starts up, and put each one into listening mode. You probably want to keep the number of pre-spawned threads/processes below the number of CPU cores (or threads) you have available.
k5054 27-Jun-20 11:58am View
   
I also initially thought that the output area was too small, but actually its not: name and job are both declared as char[20]. That means that they can each hold up to 19 chars, plus the terminating nul, so the two strings together have a max length of 38. Adding the '-' in the middle raises the maximum length to 39, which leaves one char in users for the null. Which will fit in the output area of char[40].

That being said, I suspect the OP got lucky, and didn't realize that there was a possibility for buffer overflow, which would be the case if he had separated the input strings with " - ", instead of just a single character.
k5054 30-May-20 12:55pm View
   
I've never used awk, except for the odd time when someone else's solution to a problem I was trying to solve used it, and I could copy and/or adapt to my situation. That being said, I thought there would be a awk one-liner that could get the file size. Googling around didn't provide any answers, but with a little help from a couple of different sites, I came up with this
awk 'BEGIN {sum=0} {sum+=length($0)+1} END {print sum}'

If you were going to stick with an awk only solution (probably out of sheer obstinacy), is there anything better?
k5054 19-May-20 10:50am View
   
Better yet, use getline() e.g.
#include <stdio.h>
#include <stdlib.h>

char *input = NULL;
size_t len = 0
ssize_t input_len;

input_len = getline(&input, &len, stdin);
/* ... process input ... */
free(input);
k5054 18-May-20 11:57am View
   
Did you save it? :wq or ZZ to close and save. You should have an A.cpp in the directory you are currently in unless you do not have write permission to the directory and then vim should say Can't open file for writing
k5054 18-May-20 11:18am View
   
That depends. How did you create the file to begin with? Did you use an IDE? If you did, then the IDE should be able to compile the project without you having to go to the command line. If you used an editor, e.g. nano or vi, from the command line, then when you saved the file, it should be in the same directory. If you launched an editor like gedit from the start menu, then when you selected "Save", it should ask you where you want to save it. Maybe you saved to Documents/A.cpp?
k5054 8-May-20 12:02pm View
   
or fflush(stdout) if you don't want to move the cursor to a new line. I'd also say maybe use fputs(stdout, "\n"), so as not to incur the overhead of printf if you don't need to, but I've seen compilers optimize that out for at least 15 years, so its really a matter of taste.
k5054 17-Apr-20 8:27am View
   
gcc under linux and clang FreeBSD both report long double with size as 12. I wonder what MinGW says.

Update: that was for 32 bit executables. gcc for 64 bit reports sizeof long double as 16

Update 2: MinGW-64 also reports long double as 16 bytes.

Update 3: discussing of MSVC and MinGW long doubles here: MinGW-w64 - for 32 and 64 bit Windows / Bugs / #675 difference between way vc++ and gcc converts ascii to long double, gcc wrong[^
k5054 16-Apr-20 16:49pm View
   
Quote:"(float) 1 / 2" understands the compiler as "divide float 1 with 2 as float ". So it get 0.5.

More explicitly
(float)1/2
is equivalent to
(float)1/(int)2
What the compiler does here is convert (int)2 to (float)2 then performs the division.
These days though, the compiler probably converts both (float)1 and (int)2 to double, performs the division, and then performs another conversion from double to float.

In general, I think the recommendation is to use double for floating point values unless you have memory constraints or there are some issues in your problem domain that makes float a better fit. In fact, in modern C/C++ a floating point literal such as 2.71 is a double, unless suffixed with f or F for float or l or L for long double
k5054 10-Apr-20 11:26am View
   
What does Professor::name[0] hold after adding it to the vector?
Why?
Also check the value of role and subject.
k5054 5-Apr-20 14:31pm View
   
Maybe you can post the exact problem you are trying to solve? As stated it would appear that you need to be able to calculate values in with a magnitude of the order of 1E+900000. That value is far too large for even a long double in 64 bits which would be of the order 1E+4932, so there must be some other constraints on the problem, OR you are expected to use a bignum library to compute the values.
That being said, you should also post your code. We are quite happy to review your solution and suggest fixes, but we don't provide solutions outright.
k5054 1-Apr-20 14:59pm View
   
Looks like scanf("%c%*s") doesn't quite do what I expected. Maybe try using getchar() instead. If you do that, don't forget that you need to still read the trailing '\n' on the line, and any other chars that the user may have entered. A while loop should do the trick.
k5054 28-Mar-20 11:52am View
   
In what way does this "not work properly"?
k5054 27-Mar-20 21:00pm View
   
Although MySQL seems to allow math on non-numeric columns, using text or varchar() for columns that should only have numeric values may lead to problems in the future.

Please give us some indication as to what errors you are getting with your code. We're not mind readers, and most of us probably won't try to recreate your schema to help you.
k5054 24-Mar-20 9:18am View
   
5ed for the first sentence alone.
k5054 11-Mar-20 14:53pm View
   
Show us your work, and someone here will probably give you some hints to improve your solution. But we're not going to do the work for you.
k5054 26-Feb-20 14:44pm View
   
We're not going to compile your code and fix your errors for you. You should tell us what "mistakes" you have, and where they are in the code. Perhaps then someone will point you towards a solution.

That being said, there's no body to your main(), so at best the program just exits, assuming it compiles cleanly.
k5054 25-Feb-20 21:41pm View
   
Please don't edit other peoples replies with your own comments. It makes it hard to comment and it borders on rudeness.

Please take a look atthis[^] code. This works as one would expect:
07:19:42 $ ./tcp-echo 9999
Server is listening on 9999
^C
07:19:45 $ ./tcp-echo 9999
Server is listening on 9999
^C
07:19:47 $ ./tcp-echo 9999
Server is listening on 9999
^C
07:19:49 $ ./tcp-echo 9999
Server is listening on 9999
^C
07:19:50 $ 

as you can see, this works as expected. Even if I kill -9 the server, the next invocation works.
I've even tried this by binding to a specific address using inet_aton() with no change in behaviour.
Compare this with what you are doing, and see if it provides a clue as to what you are doing wrong. If it doesn't work, then something is holding the port open between invocations. Take a look at what sudo netstat -tlnp has to tell you.
k5054 16-Feb-20 11:40am View
   
The link posted here is for C++ formatting, while the program is in C, and uses printf(). Google can help find a tutorial, if the OP needs it.
k5054 12-Feb-20 16:39pm View
   
Deleted
I'm not sure that even _Decimal128 is sufficient Given:
_Decimal128 m = 0.199848000000000DL;
    _Decimal128 n = 4.974384208042620DL;
    _Decimal128 result = m * n;
    _Decimal128 expected = 0.99412293432154732337566954206DL;

    if( r == e )
        printf("Good\n");
    else
        printf("Bad\n");

I get the result "Bad" :( Besides which the GCC manual says that there are conversion routines for integers and floating point, but there's no other way to get a printable result that I know of, since _Decimal types are not yet supported by printf(). So you're faced with a loss of precision on output, which seems to defeat the whole purpose.
k5054 12-Feb-20 13:32pm View
   
Yeah, that's because one should not use _popen() in a windows desktop context. See the note near the bottom of this document _popen, _wpopen | Microsoft Docs[^] The follow the link at the end of the note about creating child processes in a windows program. Better yet, follow Rick York's advice and use the IP helper API.
k5054 12-Feb-20 6:23am View
   
k5054 1-Feb-20 20:36pm View
   
"My main problem is that the result variable in the last [if] works very well but not as supposed"

Please explain. What were you expecting, what are you getting, and why does this not meet your expectations? Maybe also include some sample input.
k5054 21-Jan-20 21:21pm View
   
well, you could fflush(stderr).
Or you could use the code snippet above. sterror() returns the error string associated with the current errno, so my perror_cpp duplicates the functionality of perror(), but sends the output through std::cerr. Note that in the code given, the final << std::flush probably isn't strictly necessary, since std::endl is supposed to do a flush, too.
k5054 21-Jan-20 12:47pm View
   
I haven't tried this, but maybe turn off buffering for both cerr and cout: more info here https://stackoverflow.com/a/156413
k5054 17-Jan-20 21:02pm View
   
You're using realloc incorrectly. If the new size parameter to realloc is larger than the current size of the pointer passed in, then one of three things happens:
1) if there's space available, then the size of the current item is increased. The current value of the pointer will be returned
2) if the new size is larger would overflow to another allocated item, but there is space available for the new item, then new space is allocated, the contents of the current pointer are copied to the new space, and the old space is freed. The value of the new memory area is returned
3) if there is no more memory available, NULL is returned, the contents of the current pointer are not changed or freed

What this means is that code like
ptr = realloc(ptr, new_size);
may fail in unexpected ways. In particular, if realloc is unable to find new space, then ptr will now be NULL, which probably means that you've lost the pointer you did have, and you're leaking memory.What you should do is this
void *tmp_ptr = realloc(ptr, size);
if(tmp_ptr == NULL) {
    // handle error somehow 
}
else
    ptr = tmp_ptr;
// continue processing
k5054 15-Dec-19 21:19pm View
   
To the OP, also note that open("my_file.txt", O_RDONLY) does not create "my_file.txt", if it does not already exist. For that you will need to use the O_CREAT flag. There being several reasons that open might fail, you should probably check its return value e.g.
int fd;
fd = open("my_file.txt", O_RDONLY)
if(fd == -1) /* open failed */
{ 
    // handle the error here ...
}
k5054 9-Dec-19 10:19am View
   
Maybe try replacing the hyphen with the hex code (%02d), eg dev%02dredirector=.
k5054 30-Nov-19 7:25am View
   
You will need to add some context. Show the code - or at least enough of it so we can see what might be generating the error. What you've given us is like texting the doctor "it hurts when I do this"....
k5054 28-Nov-19 11:31am View
   
You said that "each person is only able to join one team per year". So that means that you can use (ID, YEARJOINED) as a primary key, and a primary key is, by definition, unique for a given table.
If I've misunderstood, and a player can join more than one team each year, then you will have to add a generated PK for the table (e.g an "identity" (MS SQL) or "auto_increment" (MySQL), or maybe extend the YEARJOINED to DATEJOINED (YYY-MM-DD) or DATETIMEJOINED (YY-MM-DD HH:MM:SS)
k5054 28-Oct-19 11:40am View
   
C++ uses "pass by value" by default. That means that when you have
void foo(vector<string> words)
{
   ...
}
int main()
{
    vector<string> v;
    foo(v);
}
the call to foo() creates a copy of vector v, passes that to foo(). When foo() returns, the copy is destroyed. What you want to do is use pass by reference. Look up references in C++.
k5054 28-Oct-19 11:23am View
   
Why make things more complicated than they have to be? Still, if you insist then:
string s;
while( !fs.eof() ) {
    ch = fs.get();
    if(ch == ' ') {
       v.push_back(s);
       s.erase();
    } else {
       s += ch;
    }
}

Note that both CPallini and I have given very similar answers, so that might be a clue how an experienced developer might approach the problem. You might want to think about why you want to read a single char at a time. Note that for large files, reading single characters at a time may be significantly slower than reading word by word.
k5054 10-Oct-19 11:40am View
   
Since this is "Run Length Encoding", one would expect that you would be able to "decode" the output in some way, and get the original text back. What you have produces the same output for any combination of 5 a's and 2 b's, as long as the first character is an a. That means you've lost information when "encoding", which is probably not what you want.
k5054 10-Oct-19 11:00am View
   
What happens when you try the input "aaabbaa"? The output should be a3b2a2
k5054 29-Sep-19 10:50am View
   
Quote:it features invalid syntax: the
Quote:
if ("%lf", &x, 0<=x<=90)
line is illegal code in C.
That line compiles with both gcc and clang, so its not illegal code. What is going on here is the Comma Operator[^] is being used to evaluate the expression. The comma operator takes an expression like (a, b, c, ...), evaluates a, b, c, ... left to right (including any side effects) and returns the value of the last term. In this case "%lf" is just a pointer to a const char *, which gets thrown away, then we have &x, which is a double *, which again gets thrown away. Then we have 0<=x<=90. While that looks like its checking to see if x is between 0 and 90 what its actually doing is evaluating as (0 <= x) <= 90. The expression (0 <x) will always evaluate to either false (0) or true (1), so the expression expression (0 <= x <= 90) will always evaluate to true, regardless of the value of x;

All the pedantic stuff out of the way, though, I'd have to agree that the code is, conceptually at least, wrong. I'm not sure what the OP was thinking when he wrote the if statement, but clearly there was some misunderstanding of how an if statement should be written. I must confess, though, it took me a little while to figure out why 0 <= x <= 90 was always true. Its a subtle mistake, and I'm sure I've made it myself in the past, and may make it again in the future. And I'm willing to bet I'm not the only one.
k5054 28-Sep-19 14:17pm View
   
Also you might want to consider using else e.g.
if(condition1) {
  // do something
}
else if(condition2) {
  // do something
} else  {
   // do something if all other if's fail
}
k5054 28-Sep-19 14:12pm View
   
Right!
k5054 28-Sep-19 14:11pm View
   
Deleted
You'll have to think about that a bit. Why does 0 <= x <= 90 evaluate to true when x = 250? You should probably look at the warnings generated by your compiler to figure this out. If you're not getting any warnings, then take a look at your compiler reference docs and see how to turn them on.
k5054 28-Sep-19 13:33pm View
   
if ("%lf", &x, 0<=x<=90)

That's not how you write an if statement. Go back and look at sample if statements from your study material. You should be able to work it out.
Edit: In particular what does 0 <= x <= 90 evaluate to. Its not what you think.
k5054 27-Sep-19 11:21am View
   
1) in the first example, array A is a valid 4x5 array. The compiler will initialize the unspecified columns to 0.

2) NULL is not synonymous with integer value zero, and should not be used to initialize int values. Your compiler should warn you about an incompatible pointer to integer conversion.
k5054 6-Sep-19 14:40pm View
   
Don't forget about srand(). Note that the code given on the MS Docs link does have one issue: because it uses time() to seed rand, it can produce identical results if the program is run more than once within the same second. In general, there's probably a pretty small chance of that happening, but it is something to be aware of, should circumstances require.
k5054 14-Aug-19 9:36am View
   
Interesting -- g++ says error: declaration does not declare anything [-fpermissive], clang OTOH says warning: declaration does not declare anything [-Wmissing-declarations]. I wouldn't call it a forward declaration, though, as it doesn't provide anything useful at all.
k5054 7-Aug-19 12:41pm View
   
If we have a function compare(string1, string2) then compare("2018-08-01", "2019-07-02") will show the first string is less than the second. That's probably what we want. If we use "mm-dd-yyyy",then compare("08-01-2018", "07-02-2019") shows the first string is greater than the second, which is probably not what we want. If we wanted to compare dates using "mm-dd-yyyy", we'd have to write a compare_date(date1, date2) function that extracts, year, month, day from each string and then compares the years, months, and days to determine if date1 is less than date2.
k5054 23-Jun-19 11:26am View
   
At the risk of confusing the OP, I'd argue that the first argument is, indeed, "passed by reference", but not "passed as a C++ reference". The term "passed by reference" in Computer Science is used to indicate when an argument is passed by pointer, and so is modifiable in the subroutine. This contrasts with"passed by value", where a copy of the value is passed in, and any changes made in the subroutine are not reflected in the caller.
k5054 21-Jun-19 12:31pm View
   
Check the firewall on the laptop, and also the pi. FTP listens on port 21, which should be open for your local LAN. If you haven't already done so, do some other basic network troubleshooting, like confirming that you can ping the laptop from the pi. If filezilla is running correctly on the laptop, you should be able to use the commandline ftp client on the pi to connect and transfer a file. If all that seems fine, then I would create a new question asking the python experts what the problem is.
k5054 28-May-19 10:50am View
   
We'll need the detail of why the ngix service failed. As the error message shows you'll need to run the commands systemctl status ngix.service and jornalctl -xe and see what the output says.
k5054 20-May-19 11:15am View
   
2nd comment on aleatoryNumber. There are all sorts of problems with rand() in general. See the first 11 minutes of this: rand() Considered Harmful | GoingNative 2013 | Channel 9[^] for a good rundown of the issues with rand(). The remainder of the video covers the <random> header introduced in C++11, so might be worth watching for those wanting better random number generation.
k5054 20-May-19 10:36am View
   
Just a quick note on aleatoryNumber(): This function calls srand() every time, which resets the random number machinery for each call to aleatoryNumber(). In this case, it appears that aleatoryNumber() is only called once, so that's not a huge issue. However if you had something like
int r1 = aleatoryNumber(10);
int r2 = aleatoryNumber(10);

you might be surprised that r1 == r2 is true more often than not.
k5054 28-Apr-19 20:02pm View
   
I think you need to look at the condition expression of your for loops:
for(initial;condition;increment)
k5054 25-Apr-19 15:33pm View
   
Turns out that recursing on main() is explicitly prohibited in C++. That's another situation where a valid C program would not be a valid C++ program.
k5054 25-Apr-19 12:49pm View
   
Quote:The main function can never be used in a recursive manner because main is a special function, it is the entry point of your program.

That's not strictly true. main() is a function like any other, and is actually called from crt0, the c run-time startup code (at least in a unix-like environment). The following code will compile and run:
#include <stdio.h>

int main(int argc, char **argv)
{
    if(argc == 1) {
        return 1;
    }
    else {
        return 1 + main(argc-1, argv+1);
    }
}

That being said, calling main() recursively is something that would require a very special set of circumstances - so don't do it unless you really, really, really need to, and understand the consequences of doing so.
k5054 23-Apr-19 18:02pm View
   
Still wrong, even b = a + (--a)
evaluates differently in gcc and clang. I think a true language lawyer would point out that this is undefined behavior, and so the implementation is free to do what it wants. Making hairy demons fly out of your nose, or launching nuclear missiles at Mount Doom in Mordor are both possible options. Neither are likely, but not prohibited by the standard.
k5054 23-Apr-19 17:52pm View
   
You're welcome.
You should probably make friends with your debugger, an indispensable tool for any programmer. Also, think carefully about your variable name - using single letter variables has its place, but normally you'd want to use something that conveys information about what the variable's intended use is. If you need to review your code several months in the future you might be scratching your head wondering what the variable 'o' is supposed to be doing for you.
k5054 23-Apr-19 16:58pm View
   
Its not deterministic, though, is it? The same compiler could evaluate the operands in different order at different optimization levels. Worse, if you're hoping to create portable code, which might be compiled on other systems, perhaps with compilers you don't have access to, not knowing that the order of evaluation is up to the compiler, is going to cause bugs.
k5054 23-Apr-19 16:15pm View
   
This is not correct. The C standard does not specify the order in which operands are evaluated. Given the following program:
#include <stdio.h>
int main()
{
    int a = 10;
    int b = a + --a;
    printf("%d, %d\n", a, b);
    return 0;
}

Compiling with gcc I get the result 9, 18;, but when I compile with clang I get 9, 19. Additionally, clang tells me: foo.c:6:17: warning: unsequenced modification and access to 'a' [-Wunsequenced], and using -Wall gcc tells me foo.c:6:17: warning: operation on ‘a’ may be undefined [-Wsequence-point]
k5054 11-Apr-19 23:34pm View
   
You need to have either a GUI or a CLI (Command Line Interface), otherwise, how will you interact with your OS?

There's various distributions that can be installed without a GUI, to which you can then add a C compiler. You'll also want to add a text editor to write your programs with.

If linux isn't to your liking, then maybe something like FreeDOS would work. You'll still need a C compiler and a text editor.
k5054 9-Apr-19 12:43pm View
   
First, have you tried to explicitly use http rather than allowing the browser to assume https e.g. http://localhost/Documents/Magazine. If your browser insists on converting http to https, try googling for something like make chrome stop redirecting http to https, and see if that helps.
Otherwise, I think you either need to configure the web server to accept https connections, or install something like stunnel, which maps unencrypted connections to SSL.
k5054 31-Mar-19 10:58am View
   
You need to pass the same password and salt to get identical outputs e.g.
k5054@debian:~$ echo "the encrypted message is this" | openssl enc -aes-256-cbc -a -salt 
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX1+SWiZRzt/w0ZkUz3EjOFTiVtibL9m+gEeyrdtpNap3MNLS/SoWhkKP
k5054@debian:~$ echo "the encrypted message is this" | openssl enc -aes-256-cbc -a -salt 
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX19wGMNxrjGSdAXVw6cDCWTlMc9gGbVIOnf+R4DTZ7vRS7Liabcglpm9
k5054@debian:~$ echo "the encrypted message is this" | openssl enc -aes-256-cbc -a -salt 
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX1/x2Om88MSlWgHtzEuarh8UIMOHo4aA63OA8ruhRbJr4ba6/vPEv1Pr

Further, assuming that the expected string is correct when trying to decode I get
k5054@debian:~$ echo "U2FsdGVkX190A5FsNTanwTKBdex29SpnH4zWkZN+Ld+MmbJgK4BH1whGIRRSpOJT" | openssl enc -aes-256-cbc -d -a -salt
enter aes-256-cbc decryption password: [enter pass]
bad decrypt
140066702831680:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:536:
<gibberish removed>k5054@debian:~$ 

so I suspect you are not using the same password between the two runs. Try using openssl enc -a aes-256-cbc -a -S 0102030405060709 -k pass
to generate your expected encrypted string. More troublesome, though, is the fact that your two strings are of different lengths.
k5054 29-Mar-19 20:04pm View
   
Humor: [xkcd: Exploits of a Mom](https://xkcd.com/327/)
k5054 28-Mar-19 14:13pm View
   
Also, are you doing this on Window or Linux? GCC isn't usual for Windows, but the term DLL is not normally used in Linux to refer to shared libraries.
k5054 27-Mar-19 13:53pm View
   
ie.
long long license = 12345678987654321L;
printf("%020lld", license)


output 00012345678987654321
k5054 18-Mar-19 15:51pm View
   
Why not?
k5054 18-Mar-19 14:25pm View
   
RHEL 6 ships with g++ 4.4, which doesn't include c++11 standard, just c++0x. The docs for both gcc4.8 (RHEL7) and gcc4.4 indicate that c++0x/c++11 was still a work in progress.
Can you build and install the latest gcc (8.3)? That claims to be fully compliant with c++11 standard, plus c++14 and c++17 too, so it might be worth upgrading.
k5054 10-Mar-19 10:16am View
   
Hahaha
The number one link on that search now points ... right back here!
k5054 8-Mar-19 14:47pm View
   
Does this point you in the right direction? https://en.wikipedia.org/wiki/Category:String_similarity_measures
k5054 8-Mar-19 13:00pm View
   
If you're processing payments you probably need to be aware of PCI compliance and GDPR compliance. Ideally, you'll pass as much processing as you can off to a payment processing service, as Richard suggested. The big thing is to make sure that payment account details (card/account numbers, PIN numbers, etc), are not stored in plain text anywhere --- and preferably not stored at all, even if you encrypt the data. Just pass all that detail off to the payment processor, and have the app forget it as quickly as possible.
k5054 30-Jan-19 13:03pm View
   
Just a quick note - make does have implicit rules for compiling and linking c++ sources. The default C++ compiler is CXX, which uses the CXXFLAGS variable to pass C++ specific flags to the compiler. If you had a Makefile that looked like
CXXFLAGS = -std=c++11 $(shell pkg-config --cflags opencv4)
LDLIBS=$(shell pkg-config --libs opencv4)

Then you could compile one.cpp to an executable by saying make one. Note that make doesn't know that multiple .o files from C++ sources need to be linked with libstdc++ so you still need to let make know it needs to use the C++ compiler to link with. In that case your target can be simplified to
foo: foo.o bar.o baz.o
        $(CXX) $^ $(LDFLAGS) -o $@

This will generate foo.o, bar.o and baz.o from foo.cpp, bar.cpp and baz.cpp as needed, and then link them all together with into the executable foo.
k5054 25-Jan-19 9:38am View
   
You've added a dependency to your lib. That's not unusual. If you're using any of the standard C functions like printf() or fopen(), then you have a dependency on the standard library. What this means is that when you want to use the lib, you'll need to remember to link in the third party lib, and deploy the third party lib with the any executables. If you're providing the lib to customers, then you'll need to document the dependency. That documentation should probably include information on how to contact the provider of the third party lib to get a legal copy of it.
k5054 9-Jan-19 9:49am View
   
Looks like Borland C++ 5 is of 1997 vintage. I think <sstream> belongs to C++98. Prior to that, it looks like <strstream.h> might be what the OP requires.
k5054 3-Jan-19 12:26pm View
   
My knowledge of templates doesn't extend far beyond being able to spell it correctly!

I, too, was interested in the reasons for that syntax and did some googling about to see what I could find. The above mentioned SO article seemed to explain it. If you scroll back from that there's a very long response that quotes the standard.

If you're really interested in what the standard says see http://eel.is/c++draft/temp#names-5 (more google-fu)

k5054 2-Jan-19 10:02am View
   
There's a detailed explanation of this here:
https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords/17579889#17579889

See the following comment also, which also explains the use of the template keyword in this situation
k5054 18-Nov-18 11:56am View
   
Since the OP seems to be only interested in the number of lines, and not the contents of the lines, why not use an fread() loop, and just count the number of newlines in the returned string?
k5054 26-Feb-18 13:20pm View
   
You need to seed the random number generator, otherwise you always get the same sequence. This is done by calling srand(). I often use srand(time(0)) i.e. seed the random number generator with the current time, in seconds. That works under linux and probably mac-os too. Windows may do things differently.
k5054 24-Jan-18 18:59pm View
   
A little more information, please. What is your CPU/system architecture, and what piece of software are you trying to compile?

At a guess, you've compiled the library (libgpstk.a) in 32 bit mode and are trying to link it into a 64 bit build (or vice versa). It also might be that your library is for an x86 but you are on an ARM, so that won't work either.
k5054 9-Nov-17 11:19am View
   
If you use single quotes around the entire block, you can omit the escapes for the double quotes
eg
VHOST='<VirtualHost *:80>
    DocumentRoot "/var/www/html/${PROJECTFOLDER}/public"
    <Directory "/var/www/html/${PROJECTFOLDER}/public">
        AllowOverride All
        Require all granted
    
<virtualhost>
'
k5054 25-Oct-17 15:06pm View
   
You have z = x < 10 The expression (x < 10) is false, since x == 10. In C, False is zero, and True is Non Zero.

What did you expect the value of z to be?
k5054 18-Oct-17 12:14pm View
   
Check your while loop in display(), and see if you can figure out why it does not terminate.