c

AudioQueue ate my buffer (first 15 milliseconds of it)

I am generating audio programmatically. I hear gaps of silence between my buffers. When I hook my phone to a scope, I see that the first few samples of each buffer are missing, and in their place is silence. The length of this silence varies from almost nothing to as much as 20 ms. My first thought is that my original callback function ...

Reading Binary file in C

Hi All, I am having following issue with reading binary file in C. I have read the first 8 bytes of a binary file. Now I need to start reading from the 9th byte. Following is the code: fseek(inputFile, 2*sizeof(int), SEEK_SET); However, when I print the contents of the array where I store the retrieved values, it still shows me the ...

How are two-dimensional arrays formatted in memory?

In C, I know I can dynamically allocate a two-dimensional array on the heap using the following code: int** someNumbers = malloc(arrayRows*sizeof(int*)); for (i = 0; i < arrayRows; i++) { someNumbers[i] = malloc(arrayColumns*sizeof(int)); } Clearly, this actually creates a one-dimensional array of pointers to a bunch of separate ...

What is a NULL value

I am wondering , what exactly is stored in the memory when we say a particular variable pointer to be NULL. suppose I have a structure, say typdef struct MEM_LIST MEM_INSTANCE; struct MEM_LIST { char *start_addr; int size; MEM_INSTANCE *next; }; MEM_INSTANCE *front; front = (MEM_INSTANCE*)malloc(sizeof(MEM_INSTANCE*))...

Is ansi c supports windows graphics?

i want to make a windows application in ansi c but suffering with graphic usage is ansi c able to handle the graphics of windows without using any extra lib. guide line required. ...

i find a problem using atoi() method in ansi c?

i have a string initialized by {'\0'} every time i a loop and store some chars in it ranging from 0 to 9 when i convert atoi(temp) where temp="2" it returns me 20 instead of 2 what i have to do to get the accurate values, help required. ...

C : crypt function

Hi all, I have used the crypt function in c to encrypt the given string. I have written the following code, #include<stdio.h> #include<unistd.h> int main() { printf("%s\n",crypt("passwd",1000)); } But the above code threw an error ,"undefined reference to `crypt'". What is the problem in the above code. Thanks in advance. ...

valgrind complains doing a very simple strtok in c

Hi I'm trying to tokenize a string by loading an entire file into a char[] using fread. For some strange reason it is not always working, and valgrind complains in this very small sample program. Given an input like test.txt first second And the following program #include <stdio.h> #include <string.h> #include <stdlib.h> #include <s...

Prevent committing code with svn if certain obsolete C/C++ functions are used

Is there a way to prevent developers from committing code when certain unsafe or obsolete functions are used? For example: scanf atoi gets etc.. ...

I want to know the behaviour of break statement in C. Does it work only for ';for-while-do-switch' or also for 'if-statements' ??

Suppose, I have a 'if statement' inside a 'for-loop'. for( ; ; ) { if( ) { printf(" inside if"); break; }//if printf("inside for"); }//for Now, will the 'break-statement' cause the compiler to come out of the 'for-loop' or will it only come out of the if loop on the 'if-condition' being satisfied. ...

What are the C functions from the standard library that must / should be avoided ?

I've read on stackoverflow that some C functions are 'obsolete' or should be 'avoided'. Can you please give me some examples of this kind of functions + the reason why. What alternatives of those function exists ? Can we use them safely - any good practices ? Later edit: From the answers: gets : can cause buffer overflows. scanf : f...

Conversion from Byte to ASCII in C

Hi All, Can anyone suggest means of converting a byte array to ASCII in C? Or converting byte array to hex and then to ASCII? [04/02][Edited]: To rephrase it, I wish to convert bytes to hex and store the converted hex values in a data structure. How should go about it? Regards, darkie ...

Fastest way to calculate a 128-bit integer modulo a 64-bit integer

I have a 128-bit unsigned integer A and a 64-bit unsigned integer B. What's the fastest way to calculate A % B - that is the (64-bit) remainder from dividing A by B? I'm looking to do this in either C or assembly language, but I need to target the 32-bit x86 platform. This unfortunately means that I cannot take advantage of compiler sup...

What is the use of typedef?

What is the use of typedef keyword in C ? When is it needed? ...

How to make C program wait (on Linux) ?

How to make C program wait (on Linux)? (I need to use wait with MPI - I need C code please) ...

Is there a way to translate C code to Ruby?

I'm sitting with massive amounts of legacy C code that needs to be converted to Ruby for a project. I've seen Ruby to C translators online, but not the other way around. Would there be a simple way to approach this particular problem? ...

Where to find __sync_add_and_fetch_8?

I got errors when trying to use __sync_add_and_fetch: test8.cpp:(.text+0x90e): undefined reference to `__sync_add_and_fetch_8' collect2: ld returned 1 exit status Please kindly advise how to rectify this. Specs: GCC/G++: 4.4.1 GNU/Linux 2.6.32 SMP i686 Many thanks! EDIT: In addition to the answer provided, one can use -march=i586 ...

How to reverse bitwise AND (&) in C?

How to reverse bitwise AND (&) in C? For example I have an operation in C like this: ((unsigned int)ptr & 0xff000000)) The result is 0xbf000000. What I need at this moment is how to reverse the above, i.e. determine ptr by using the result from the operation and of course 0xff000000. Is there any simple way to implement this in C? ...

Why do i get segfault at the end of the application after everything's been done properly ?

#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char pass[] = "m4ak47"; printf("Vnesi password: \t"); scanf("%s", stole); if(strncmp(stole, pass, sizeof(pass)) != 0) { printf("wrong password!\n"); exi...

What alternatives to __attribute__ exist on 64-bit kernels?

Hi: Is there any alternative to non-ISO gcc specific extension __attribute__ on 64-bit kernels ? Three types that i've noticed are: function attributes, type attributes and variable attributes. eg. i'd like to avoid using __attribute__((__packed__)) for structures passed over the network, even though some gcc based code do use it. An...