243 Answered Questions for the topic C

C

06/25/19

Why aren't programs written in Assembly more often?

It seems to be a mainstream opinion that assembly programming takes longer and is more difficult to program in than a higher level language such as C. Therefore it seems to be recommend or assumed... more
C

06/23/19

Check that triangle is right?

I'm trying to check if a triangle is a right triangle in C language. `a`, `b` and `c` are lengths of sides of some triangle. int is_right_triangle(int a, int b, int c) { return (a * a + b... more
C

06/23/19

Undefined reference to pthread_create in Linux?

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/ #include <pthread.h> #include <stdio.h> #define NUM_THREADS 5 void... more
C

06/23/19

What is ultimately a time_t typedef to?

I searched in linux box and saw it being typedef to typedef __time_t time_t;But could not find the __time\\_t definition.
C

06/22/19

How can one print a size_t variable portably using the printf family?

I have a variable of type `size_t`, and I want to print it using `printf()`. What format specifier do I use to print it portably? In 32-bit machine, `%u` seems right. I compiled with `g++ -g -W... more
C

06/22/19

Why does the smallest int, −2147483648, have type 'long'?

For a school project, I've to code the C function printf. Things are going pretty well, but there is one question I can't find a good answer to, so here I am. printf("PRINTF(d) \ : %d\ ",... more

Can we implement a doubly-linked list using a single pointer?

I want to use a structure like: struct node { char[10] tag; struct node *next; }; I want to use the above structure to create a doubly-linked list. Is that possible and if yes, then how I can... more
C

06/21/19

Including libraries in the custom code section in Simulink?

I'm trying to Include some Libraries, like `metis` in the custom code library section in Simulink. Do you know what type of libraries Simulink excepts? Must they have the ending `.a`, `.o`, `.dll`... more
C

06/21/19

Why do we need C Unions?

When should unions be used? Why do we need them?
C

06/21/19

Piketec TPT java automation?

I am trying to use TPT java api, for some automation of project. And trying to "Add step list" using function "generateTestCasesFromTestData" but couldn't figure out where to get its first... more
C

06/21/19

Simulink C-Code Generationed logic?

simple question here. I would like to examine the generated c code after it has been generated from Simulink. The problem is, I cannot find any of the logic code, or variables from the model. I've... more
C

06/20/19

Removing trailing newline character from fgets() input?

I am trying to get some data from the user and send it to another function in gcc. The code is something like this. printf("Enter your Name: "); if (!(fgets(Name, sizeof Name, stdin) !=... more
C

06/20/19

How to initialize a struct in accordance with C programming language standards?

I want to initialize a struct element, split in declaration and initialization. This is what I have: typedef struct MY_TYPE { bool flag; short int value; double stuff; }... more
C

06/20/19

What do people find difficult about C pointers?

From the number of questions posted here, it's clear that people have some pretty fundemental issues when getting their heads around pointers and pointer arithmetic.I'm curious to know why. They've... more
C

06/19/19

Need help programming with Mclauren series and Taylor series?

Ok so here's what i have so far: #include <stdio.h> #include <math.h> //#define PI 3.14159 int factorial(int n){ if(n <= 1) return(1); else return(n *... more
C

06/16/19

ssSetOutputPortWidth - does it allocate memory? Can we force that it is contiguous?

I am writing a C S-function in Simulink/Matlab, which fills an output buffer of size 500 kB for a later application. I have done this in <code>mdlInitializeSizes</code>: ... more
C

06/15/19

find if 4 points on a plane form a rectangle?

Can somebody please show me in C-style pseudocode how to write a function (represent the points however you like) that returns true if 4-points (args to the function) form a rectangle, and false... more
C

06/15/19

When is assembly faster than C?

One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in... more
C

06/15/19

Why are hexadecimal numbers prefixed with 0x?

Why are hexadecimal numbers prefixed as `0x`? I understand the usage of the prefix but I don't understand the significance of why `0x` was chosen.

06/14/19

How do I know what the rsp register is in Assembly?

I know that the rsp register points to the top of the stack. However, I'm not sure how I would figure out what is on top of the stack or what rsp looks like in code. For example, if I have a... more
C

06/14/19

What is the argument for printf that formats a long?

The `printf` function takes an argument type, such as `%d` or `%i` for a `signed int`. However, I don't see anything for a `long` value.

06/14/19

How do I define and use an ENUM in Objective-C?

I declared an enum in my implementation file as shown below, and declared a variable of that type in my interface as PlayerState thePlayerState; and used the variable in my methods. But I am... more
C

06/14/19

What's the best way to check if a file exists in C?

Is there a better way than simply trying to open the file? int exists(const char *fname) { FILE *file; if ((file = fopen(fname, "r"))) { fclose(file); ... more
C

06/13/19

In C, why do some people cast the pointer before freeing it?

I'm working on an old code base and pretty much every invocation of free() uses a cast on its argument. For example, free((float *)velocity); free((float *)acceleration); free((char *)label);where... more
C

06/13/19

Finding center of 2D triangle?

I've been given a struct for a 2D triangle with x and y coordinates, a rotation variable, and so on. From the point created by those x and y coordinates, I am supposed to draw a triangle around the... more

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.