Why can’t I get string input?

I was trying to simulate stack concept, and this is my code, blasts errors everywhere, from the very first scanf, to everywhere referring char* variables, and eventually the stack pointer (I named it towerIndicator) doesn’t change at all. And then every typed input is somehow screwed: if I type ‘+314’ to add 314 to the stack, it eventually add 3144,…
Read more

Least cost algorithm

A string consisting of digits (0-9) is given and an integer query is given. We need to make sure that any of the digits in the string (0-9) is repeated >= query times. This is done by replacing individual digits in the string with another digit, and the cost of the operation is the difference between the replaced digit and…
Read more

forking server for handing many clients C

I have a problem with my server, i run it, and using fork, but only one client can work, the rest run but not work, i try many way to resolve, but no done http://codepad.org/1Y9e4Pri client code http://codepad.org/ODjKuKpZ server code Source: c#

What can a pointer do that a variable can’t do?

I’m learning about pointers and been told this: “The purpose of pointers is to allow you to manually, directly access a block of memory.” Say i have int var = 5;. Can’t i use the variable ‘var’ to access the block of memory where the value 5 is stored, since i can change the value of the variable whenever i…
Read more

How to enforce garbage collector to call finalize method first, before cleaning up reference of unused objects

I have a scenario which uses a C library using JNA: I have override the finalize method where I send the call to delete the object that is created through C. My code looks somewhat like this: protected void finalize() throws Throwable { if (LicensingAPIHelper.instance == null) throw new NullPointerException(“LicensingAPIHelper is not initialized”); LicensingAPIHelper.instance.sntl_licensing_app_context_delete(nativeAppContext.getValue()); } sntl_licensing_app_context_delete is the API, which…
Read more

Write Function in C

The Question is: Write a function which takes a sorted list and groups equal values into a group(a list) and therefore returns a list of lists example: group([1, 1, 1, 2, 2, 3, 4, 4, 4, 5]) == [ [1, 1, 1,], [2, 2], [3], [4, 4, 4], [5] ] & what i did is #include<stdio.h> void group(int a[]); int…
Read more

Prompt error message if user choose 1 before 2 in a menu in C

I have a code written in C where I need the user to choose between 4 different choices in a menu. My code looks like this: while(t!=0) { printf(“——————-MENU—————————n”); printf(“1. Randomize array.n”); printf(“2. Sort array in ascending order.n”); printf(“3. Print min- and max value.n”); printf(“4. Search for a number in the array.n”); scanf(“%d”,&t); switch(t) { case 1: randomize(array); print(array); break;…
Read more

Bit field memory management in C

To understand the bit field memory storage, I have created the test program below. #include <stdio.h> int main() { int a; typedef struct { int b7 : 1; int b6 : 1; int b5 : 1; int b4 : 1; int b3 : 1; int b2 : 1; int b1 : 1; int b0 : 1; } byte; byte ab0…
Read more

Making a connect 4 game in C

Hi all so for a small project we need to make a connect four game, our project is broken up into several parts with each week we are assigned a different part to work on. This week we have to make up the work on the columns by this I mean we have to use a function is called get_column,…
Read more

OpenGL use in a headless embedded linux platform

In our project we want to use the GPU of a Freescale iMX6Q ARM processor to render an image and then write over a gstreamer pipeline to a VNC server. The sequence is as follows: Initialize OpenGL For each frame of the video stream: Render Image with OpenGL ES to a texture using a Framebuffer and a Renderbuffer Read Image…
Read more