Click here to Skip to main content
14,641,178 members

Comments by k5054 (Top 84 by date)

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 ... */
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
is equivalent to
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?
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
07:19:45 $ ./tcp-echo 9999
Server is listening on 9999
07:19:47 $ ./tcp-echo 9999
Server is listening on 9999
07:19:49 $ ./tcp-echo 9999
Server is listening on 9999
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
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 )

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
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 
    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;
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 == ' ') {
    } 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
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
k5054 28-Sep-19 14:11pm View
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:
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:
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:
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:

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](
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
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
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?
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 (more google-fu)

k5054 2-Jan-19 10:02am View
There's a detailed explanation of this here:

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
VHOST='<VirtualHost *:80>
    DocumentRoot "/var/www/html/${PROJECTFOLDER}/public"
    <Directory "/var/www/html/${PROJECTFOLDER}/public">
        AllowOverride All
        Require all granted
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.
k5054 8-Sep-17 11:11am View
Maybe take a look at how your system launches sshd. On my CentOS 7 system that shows as


How you get there will depend on if your system is using inittab, upstart or systemd to launch processes from init.
k5054 7-Sep-17 11:42am View
On the other hand, in function reduction() you modify data[], but do not reset it, so you're getting the wrong answer when you call reduction_media().
k5054 7-Sep-17 11:13am View
Decimal is quite slow, you may be able to get better results using double, or if your compiler supports it, long double.

On my linux box, compiling in 64 bit mode, I have the following:
float: 24 bit mantissa ~ 6 decimal digits
double: 53 bit mantissa ~ 15 decimal digits
long double: 64 bit mantissa ~ 18 decimal digits

If that's not appropriate for your use case, then you may wan to look at an arbitrary-precison math library, like GMP or MPFR.
k5054 8-Aug-17 18:58pm View
That should be memcpy(a, &s, sizeof s)

Note that sizeof only needs brackets if its operand is a type rather than a variable.

It should also be pointed out that in this case the contents of a[] are not human readable.
k5054 8-Aug-17 18:47pm View
Couple of notes

snprintf writes at most size bytes, including the terminating null byte to the destination, so you don't need to manually account for it.

you forgot to include the dob member when printing the date of birth. So we end up with the following:
snprintf(buffer, sizeof buffer, "%s, %d, %02d:%02d:%02d",       ps->name, ps->rollNumber, ps->dob.yy, ps->, ps->dob.dd); 
k5054 7-Aug-17 18:09pm View
I think you're confused. Knights move in an L shape. You're thinking of a Queen which can move in any direction.