Splint: local variable used before definition

I know local variables can have "random" value when not set, but is it bad to set the first value of a local variable with a pointer? For example: void setValue(int* p_val) { *p_val = …; /* Assignment does not use *p_val */ } int main(void) {...
more »

2017-12-01 14:12 (1) Answers

Assignment to expression with array type C

I have this assignment for my Algorithms class to write a system for a car dealership that allows them to search through their inventory so that the complexity of the search is not O(n). To solve this I chose to use a binary search tree that points t...
more »

2017-11-26 18:11 (2) Answers

Can't store a struct containing a pointer

I have three structs : struct Map { int width, height; int* cases; }; typedef struct Map Map; struct Ship { int x, y, length, firstShoot, color, hasBeenDiscovered; }; typedef struct Ship Ship; struct Player { int activeShips; M...
more »

2017-11-16 15:11 (1) Answers

C - malloc and automatic storage

I understand that variables declared within a function have automatic storage. Does this mean it's not necessary to free pointers (p below) that have been explicitly allocated within a function call using malloc? void f() { int *p; p = malloc(s...
more »

2017-11-16 01:11 (4) Answers

Size of Pointer Variables

Considering pch, pshort, pdouble declared as pointers to char ,short int ,double respectively, what would be the arrangement if the three variables were arranged according to their size ? ...
more »

2017-11-10 12:11 (3) Answers

Initialise struct pointers in a function in C

I'm fairly new to C and I'm a little confused as to the correct way to initialise struct variables which are pointers, within a function. Is this style sufficient, or do I need to allocate memory before I assign s->str? Thank you kindly for your repl...
more »

2017-11-08 21:11 (4) Answers

Array of structures of function pointers C

I'm trying to initialize an array of structures containing pointer on function : typedef struct struct_actioncommand { char *action; void (*command)(my_type); } type_actioncommand; To initialize each pointer with its function name I'm usin...
more »

2017-11-08 18:11 (1) Answers

1D array vs 2D arrays printing strings in c

I know that to print a string, we use char *pt = "Hi there"; printf("%s", pt); or char pt[] = "Hi there"; printf("%s", pt); where the array name acts like a pointer referring to the address of the first element. however when we get a 2D array ...
more »

2017-10-28 07:10 (1) Answers

Pointer as a structure variable in c

When I use code like this : typedef struct { int x; int *pInt; } tData; tData *ptData = malloc(sizeof(tData)); If i understand it right, i allocated memory with size of tData and returned adress to this allocated memory to poin...
more »

2017-10-27 12:10 (1) Answers

Assigning to postfix-incremented pointers

I have read that postfix increment and decrement operators return rvalues of the operands. Assuming that is true, how are codes like this possible?: int arr[5]{}; int *p = arr; for (int i = 0; i != 5; ++i) *p++ = i; My thought procees is Acc...
more »

2017-10-24 07:10 (2) Answers

String and String array Manipulation in c

I'm trying to write a string spliter function in C.It uses space as delimiter to split a given string in two or more. It more like the split funtion in Python.Here is the code:- #include <stdio.h> #include <string.h> void slice_input (...
more »

2017-10-21 09:10 (2) Answers