how to print variable in c struct

Please am finding it difficult to print variable b in my struct declaration sum.h #ifndef SUM_H_ #define SUM_H_ typedef struct sumTAG{ int a; int b; }Sum; void addition(); void initialize(); #endif sumtest.c #include "../headers/sum.h"...
more »

2017-04-17 16:04 (1) Answers

Trouble with changing pointer values

So I started learning C today and have had no problems making it through tutorial exercises, but I am finally stuck. I have checked stackoverflow, other reddit posts, and youtube videos. I am trying to created a linked list. Below is my code with det...
more »

2017-04-17 05:04 (2) Answers

placing an interval in an array of pointers

I tried emailing my Professor for help with this and he was not very helpful. given an interval of size 50 starting at x as [x,x+50] (x and x+50 are included), find where to place this interval so that it has the maximum number of elements pointed b...
more »

2017-04-17 02:04 (1) Answers

Converting Number to Integer

I need to get a number potentially outside the signed integer range from a string into an integer. I always get the number 0 if the value is outside the signed integer limit. I understand that 0 means the conversion failed. Here is what I've tried:...
more »

2017-04-17 02:04 (2) Answers

Segmentation fault 11 Objective-C, but not in C

I'm currently trying to create a 16 bit/channel or 48bpp image as an array in Objective-C, then put it in a NSBitmapImageRep. For a start, I want to just fill it with noise to see if it works, so I'm using a C for loop, and for some reason it creates...
more »

2017-04-16 19:04 (1) Answers

Why you mustn't write scanf("%.2lf", &a) in C?

My friend have just started learning programming. He showed me his code and asked why it return some weird number. After taking a look at it, I saw that he was using scanf("%.2lf", &a) to take input, and by habit, I try to change it to normal. Th...
more »

2017-04-16 17:04 (2) Answers

C - Split matrix into equipartitions

I'm writing an algorithm to divide a matrix into 4 submatrices(equipartitions). Size of the whole matrix is always multiplier of 4 as being shown in the added image. If you watch out, I'm trying to access elements like 1D element instead of 2D. I can...
more »

2017-04-16 10:04 (1) Answers

Sum of dices rolls

I am trying to compute the probability of getting a specific sum of n s-sided dice outcomes. I found the formula in the following link (formula 10) : http://mathworld.wolfram.com/Dice.html this is the code that i wrote in C : # include <stdio.h&g...
more »

2017-04-15 22:04 (2) Answers

Decimal to Binary convert in C

My simple program fails to convert 7 to 111 (the current code gives 101). I know myArray[] and the last printf() can be improved, but we can talk about that next time. int main() { int myDecimal, quo, rem; int i = 0; //counter int myArra...
more »

2017-04-15 09:04 (3) Answers

Evaluation of a statement in C language

struct { int a[2], b; } arr[] = {[0].a = {1}, [1].a = {2}, [0].b = 1, [1].b = 2}; How to evaluate this line in C language? General declaration of struct is different from this statement. Also accessing of an element in C can be done like [0]....
more »

2017-04-15 08:04 (6) Answers

Can I speed up this function?

I'm trying to write John Conway's Game of Life in C, but I'm having trouble adding living cells to the board. The function I wrote to handle it is extremely slow. Thought process: I want to add n living cells to the board randomly, so while cells le...
more »

2017-04-15 06:04 (4) Answers

Would linux tell me if there was a stack overflow?

Bear in mind I'm relatively new to C and linux. For one of my classes I have a project in which we are supposed to find which cities are located in a certain geographical box, we have to use binary search trees though the implementation is up to us....
more »

2017-04-14 12:04 (2) Answers

C - for loop ends early

Full code: https://pastebin.com/NpspcJB8 FILE *fptr; char regPlates[350][10]; // array of registration number plates, e.g. AA234BB switch (userInput) { case 'a': // check available spaces ReadFromFile(); CheckEmptySpace...
more »

2017-04-13 16:04 (0) Answers

Okay with newline before semi-colon?

I'm new to C programming. I write a Basic C code like #include<stdio.h> main() { int t = 5 ; printf("%d\n",t ); } Is it going to produce a error? Well, my questing is like int x = 9; and int x = //Finish this instruction in 3 ...
more »

2017-04-13 11:04 (4) Answers

Block window maximize functionality? (Completely)

I am trying to create a window with behavior similar to cmd.exe, specifically whereby I don't want to support maximizing the window, since I only show fully visible lines of text (vertically). I have come up with two solutions so far: Solution 1: c...
more »

2017-04-13 08:04 (1) Answers