Skip to content

Tag: c++

Comparing 2 files in c linux fgets

I need to compare 2 files and return 1 if they are same or 0 if not, but function always return 0. I have no idea why. Maybe you know diferent function that can do this. Answer strcmp(line1,line2)==0 means line1 and line2 are equals, your code supposes they are different There is an other error, if a file is …

Unable to connet to SQL server using soci library

I am beginner in c++,my problem on Linux for connecting to SQL Server with soci library, my code this but I have error and I don’t found solution for my problem, my code this: I have error: Here is the code: Answer Your ODBC connection string in incorrect, your first parameter specifies a datasource cal…

How to pass an extra option in ls using execv()?

I’m trying to execute this simple command ls -1 *.c using the execv() function. The output I’m getting is Answer There’s a big problem in your code: execv can’t tell how big the array you’re passing it is. You absolutely need a terminating NULL element to mark the end: OK, now th…

Why is linear search so much faster than binary search?

Consider the following code to find a peak in an array. If I compile with -O3 and use the linear search solution (the peak function) it takes: If I use the binary search solution which should be much faster (the peak_rec function), it takes: I tried turning off optimization but this didn’t change the si…

read() hangs on zombie process

I have a while loop that reads data from a child process using blocking I/O by redirecting stdout of the child process to the parent process. Normally, as soon as the child process exits, a blocking read() in this case will return since the pipe that is read from is closed by the child process. Now I have a c…

Towards understanding availability of xdg-open

I want to open an image, and in Windows I do: I would like to use a Linux approach, where it’s so much easier to run something on the fly. Example: In my Ubuntu, it works. However, when running that in Wandbox (Live Demo), or in any other online compiler, I would most likely get an error: sh: 1: xdg-ope…