c

Linked List of Intervals

Hello I have the following two questions. I'm aware of the concept of a linked list. What is a linked list of intervals? I need to store a very huge (more than 100 bits) number in C/C++ and perform bitwise operations on it. Without using any big number library, what would be the best data structure to handle this scenario ? Thank Yo...

Consumer-Producer problem

I am having a problem with my Consumer, producer program, it seems to load, but returns a segmentation error. I have tried everything to fix it but still failing!! Will be greatful for any assistance. Note; The code is really much, semaphore.h code is within, if anyone wishes to test. and the rest of the code is as is here. Am runing thi...

Knowing if function is taking reference or value at runtime

So this is a purely academic question, mostly as its been a while since I've done anything too complex in C++. But is there any way to know if a method is taking a paramter as a reference or a value? This isn't important for pointers, as if you try to pass a non-pointer to a method that takes a pointer, you get a compile error. But somet...

Problem comparing strings containing numbers

hello i got a problem with comparing two char* variables that contains numbers for example char1 = "999999" and char2="11111111" when i am using the strcmp function it will return that char1 variable is greater than char2 even tho its wrong. (i know that i can compare with using the atoi function till 9 chars inside the string but i need...

Transferring output of a program to a file in C

I have written a C program to get all the possible combinations of a string. For example, for abc, it will print abc, bca, acb etc. I want to get this output in a separate file. What function I should use? I don't have any knowledge of file handling in C. If somebody explain me with a small piece of code, I will be very thankful. ...

Difference between reading a variable using scanf and assignment

int main() { int i,j; i='c'; scanf("%d",&j); // I will read 'c' here printf("%d %d",i,j); } Output is not same.'j' takes garbage value and 'i' takes ascii value of 'c'. Can anybody tell what could be the reason ? ...

Binary Array Compression in C

I have binary array in c, I want to compress the array, kindly suggest me algorithm which compress binary array. I have used Lempel–Ziv–Welch (LZW) algorithm but its not suitable for me because there is no repetition in my data. ...

having difficulities in reading two lines of code

How to analyze these two following lines of code? w += /* 28 + */ y % 4 == 0 && (y % 100 || y % 400 ==0); and w += 30 + (i % 2 ^ i >= 8); Thanks. ...

Const return types in C

I was reading some samples of code, and they returned a const int. When I tried to compile the examples code I got errors concerning conflicting return types. So I started searching, thinking that the const was the problem (when I removed it, the code worked fine, not only did it compile, but worked as expected). But I never was able...

output transfer to a new file

I am a complete noob to c. I have downloaded a code from internet. It generates all possible combination of characters. I want to transfer this output to a text file. I have tried few things but unable to do it. Can anybody suggest me the necessary changes? Here is the code.a EDIT: I have changed the put command to fputs. i tried all po...

Any caveats in porting GNU Pth code for Pthreads?

I have code written using GNU Pth ( http://www.gnu.org/software/pth/ ) and I want to move to Pthreads because I want it to be cross-platform (Unix, Mac, Windows). Are there and caveats I should watch out for while going about switching from Pth to Pthreads, or is it mostly just a matter of realigning arguments and variable types? ...

cannot assign a value to 64-bit integer on 32-bit platform

After switching from 64-bit to 32-bit platform (both of them are CentOS) I get integer constant is too large for ‘long’ type error for the following line of code uint64_t Key = 0x100000000; Casting the value does not help. What am I doing wrong? Thanks ...

How to correctly multiply two long long ints?

I want to multiply long numbers which are given in a 2^32 basis. I already thought of an nice algorithm to do that, but unfortunatly I'm stuck. The situation I'm stuck at, is how I do multiply two long ints and represent it on the 2^32 basis. #include <stdio.h> #include <stdlib.h> #include <limits.h> typedef unsigned int uint32; typedef...

Concurrent access to struct member

I'm using 32-bit microcontroller (STR91x). I'm concurrently accessing (from ISR and main loop) struct member of type enum. Access is limited to writing to that enum field in the ISR and checking in the main loop. Enum's underlying type is not larger than integer (32-bit). I would like to make sure that I'm not missing anything and I can...

How to use glDrawVertex() function in ANSI C

Hello :) I'm learning OpenGL, and now usage of function glDrawArrays() but I always get Segmntation fault on glDrawArrays call, i'm doing something wrong? /*MESH*/ struct Mesh { GLsizei numVertices; GLfloat vertices[48]; } m; static void meshCreate(struct Mesh *mesh) { mesh->vertices[0] = 0.000000f; mesh->vertices[1] = -0.000000f;...

Are there any easy to use libraries for hashing data arrays?

I am thinking about using CRC32 or SHA1, possibly both in C program I develop on Linux (Ubuntu). Are there any easy to use libraries for either? Cutting and pasting a CRC32 algorithm into the source code of my program seems simple enough, but doing the same for SHA1 feels slightly shaky. Are there any easy to use libraries, preferably...

Why Right Associativity doesn't work with the declaration statement.

int a=b=c=10; //invalid statement But following are valid statements int a,b,c; a=b=c=10; First one is invalid as b assigned to a even before b got its value. But the second case is valid as equal(=) sign is having right associative i.e "=" sign will start getting preference from the right side. My question is: why doesn't Right ...

how to copy information from one sector to a pen drive with the help of c program ?

and if i want to access a hard disk which is containing some data and i want to copy that from one sector to another , then is it possible ? ...

fread Only first 5 bytes of .PNG file

I've made a simple resource packer for packing the resources for my game into one file. Everything was going fine until I began writing the unpacker. I noticed the .txt file - 26 bytes - that I had packed, came out of the resource file fine, without anyway issues, all data preserved. However when reading the .PNG file I had packed in the...

Add SSL support to an open source application

Hi, I need Mosquitto http://mosquitto.org to work with SSL. I've read several examples with OpenSSL, but as I've never worked with sockets in C, can someone tell me what do I have to change for my existing sockets? (Accept, write, read?) Thank you very much ...