what is Segmentation fault (core dumped)? [duplicate]

“Segmentation fault” means that you tried to access memory that you do not have access to. The first problem is with your arguments of main. The main function should be int main(int argc, char *argv[]), and you should check that argc is at least 2 before accessing argv[1]. Also, since you’re passing in a float … Read more

Categories C Tags

pthread_join() and pthread_exit()

In pthread_exit, ret is an input parameter. You are simply passing the address of a variable to the function. In pthread_join, ret is an output parameter. You get back a value from the function. Such value can, for example, be set to NULL. Long explanation: In pthread_join, you get back the address passed to pthread_exit by the finished thread. If you pass just a plain … Read more

What is *(uint32_t*)?

uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 – 1. This declares a pointer of type uint32_t*, but the pointer is uninitialized, that is, the pointer does not point to anywhere in particular. Trying to access memory through that pointer will cause … Read more

How to use execvp() to execute a command

The prototype of execvp is It expects a pointer to char as the first argument, and a NULL-terminated pointer to an array of char*. You are passing completely wrong arguments. You are passing a single char as first argument and a char* as the second. Use execlp instead: So Also the convention in UNIX is to print error messages to stderr and a process with an error should have … Read more

How to use execvp()

The first argument is the file you wish to execute, and the second argument is an array of null-terminated strings that represent the appropriate arguments to the file as specified in the man page. For example:

Working on code to calculate cosine with factorial sum

One thing I see, is that your for loop within main only runs through 2 real iterations, once for i == 0, and again for i == 1. For the taylor expansion to work fairly effectively, it needs to be run through more sequence terms (more loop iterations). another thing I see, is that your … Read more

Categories C Tags

Implementing Taylor Series for sine and cosine in C

Anything over 12! is larger than can fit into a 32-bit int, so such values will overflow and therefore won’t return what you expect. Instead of computing the full factorial each time, take a look at each term in the sequence relative to the previous one. For any given term, the next one is -((x*x)/(flag_2*(flag_2-1)) times the previous one. So … Read more