c

Issue in periodically reading contents of stdout redirected to pipe using dup2

Hi, I have to periodically read contents of stdout which is redirected to file. please help me to resolve issue. My problem in detail is that i have two thread in first thread , i have to execute a c file which is continously writing output to stdout(i.e writing hello world in infinite loop) and in second thread i have to retrieve l...

Free C programming ebook for beginner students?

Possible Duplicate: List of freely available programming books Can someone recommend a free ebook for C programming for students? preferably in PDF format. ...

Overflow Questions on floats and floats × integers

1) Is this unoverflowable? long long v1, v2, result; [..] result = ((long double) v1 / v2) * 1000000LL; 1.a) Can I leave out the LL on the constant? And why. 2) Alternatively is this variation without a float ok? long long l1, l2, result; [..] result = (1000000 * (v1 / v2) + v1 % v2); 2.a) Which has more overheads? The 1st or thi...

Identify which file has included some particular header file

Sometimes with a complex header structure it happens some header is included, but it is hard to tell where from. Is there some tool (depedency viewer?) or a method how to find the "inclusion stack" (which source / which header / which header / ...) is including one particular header file? If the header file is included multiple times, ...

Splint Code Analyzers for C

We are planning to use Splint as code analyzer for our C code base. But we never tried Splint tool before so we want your input on it's benifts, pros and cons. ...

Postfix to infix with unary/binary operators

I am trying to make a converter from postfix to infix notation and need some help. There is already a question about infix-to-postfix conversion, which gives an example I am failing to convert back. (Note: a minus sign is missing there!) The following is the output of my converter, where the 1st "column" is postfix input, the 2nd is my ...

scanf error in c while reading a character

#include <stdio.h> int main() { char TurHare; while(1) { scanf("%c",TurHare); printf("\nCharacter :%c", TurHare); } return 0; } When I compile and then run the program the output is like : w Character : w Character : where w is the input from console. It should appear like: w Character : w How t...

Memory (and other resources) used by individual VirtualAlloc allocation

How much memory or other resources is used for an individual VirtualAlloc (xxxx, yyy, MEM_RESERVE, zzz)? Is there any difference in resource consumption (e.g. kernel paged/nonpaged pool) when I allocated one large block, like this: VirtualAlloc( xxxx, 1024*1024, MEM_RESERVE, PAGE_READWRITE ) or multiple smaller blocks, like this: Vi...

Can anyone decipher why these two conversions to unsigned long long give different results?

LARGE_INTEGER lpPerformanceCount, lpFrequency; QueryPerformanceCounter(&lpPerformanceCount); QueryPerformanceFrequency(&lpFrequency); (Count.QuadPart is a long long showing a CPU count) (Freq.QuadPart is a long long showing frequency of Count for a second) Attempting to print microseconds in real time. stable output: printf("%llu\...

How to optimize this code?

Profiler says that 50% of total time spends inside this function. How would you optimize it? It converts BMP color scheme to YUV. Thanks! Update: platform is ARMV6 (writing for IPhone) #define Y_FROM_RGB(_r_,_g_,_b_) ( ( 66 * _b_ + 129 * _g_ + 25 * _r_ + 128) >> 8) + 16 #define V_FROM_RGB(_r_,_g_,_b_) ( ( 112 * _b_ - 94 * _g_ - 18 ...

How can access individual number of an array element in C ??

If I have some array element, how can I get individual numbers from the array element buffer[0]? For example, suppose I have buffer[0]=0x0605040302, I'd like to first extract 2, then 0, then 6, etc. ...

How to enable ARM1136JFS (ARM v6) MMU to have one to one mapping between physical and virtual address space?

I want to enable data cache. I dont have much experience with ARM as I have mostly programmed for IA32. My understanding is that I need to enable MMU to enable data cache. As I dont need the virtual memory other wise so I want to enable MMU with one-to-one mapping between physical and virtual address space for all applications. Any help...

Assign unsigned char to unsigned short with bit operators in ansi C

I know it is possible to assign an unsigned char to an unsigned short, but I would like to have more control how the bits are actually assigned to the unsigned short. unsigned char UC_8; unsigned short US_16; UC_8 = 0xff; US_16 = (unsigned char) UC_8; The bits from UC_8 are now placed in the lower bits of US_16. I need more control o...

How do I determine the remote endpoint a UDP packet originates from?

The socket is created and bound, then the program receives data with recv(). The question is: How do I now determine from which host + port the packet originates so that I can send data back? Note: C and Winsock is used. ...

LINUX SYSTEM() API

Hi, Can anybody tell me the output of the below code, whether "bye" will be printed or not? /* Thanks in advance */ #include <stdio.h> int main() { system("ls -l"); printf("bye"); return 0; } ...

Dot operator cost c/c++

We all know about -> vs . speed diff to access members in c/c++, but I am hard to find any clues of the actual cost of the simple dot operator. I imagine its something like address-of-struct + offset, also assume the offset being the sum of all sizeof-s of all preceding members. Is this (roughly) correct? Then compared to -> who much f...

C libcurl - measure download speed and time remaining

Hi, I am using the following code to download files from the internet: size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t written; written = fwrite(ptr, size, nmemb, stream); return written; } int main(int argc, char** argv) { FILE *downloaded_file; if ( (downloaded_file = fopen (download_path ...

Strong typedef static checker (unix)

Is there a free tool (some kind of a static checker) that does typedef-based type-checking for a plain C (not C++) and runs on Linux (or any kind of free Unix)? I am aware of a commercial one: PC-lint/FlexeLint. It does exactly what I want, but it's not free and Windows-only. Here is an example from it's manual: typedef int Count; typed...

confusion in scanf() with & operator

why do we need to put a & operator in scanf() for storing values in an integer array and not while storing a string in a char array? i.e int a[5]; for(i=0;i<5;i++) scanf("%d",&a[i]); but char s[5]; scanf("%s",s); ? we need to pass in the address of the place we store the value,since array is a pointer to first element so in the case wi...

What is the proper way of implementing a good "itoa()" function ?

First, hi, I'm new to stackoverflow ! Well, I was wondering if my implementation of an "itoa" function is correct. Maybe you can help me getting it a bit more "correct", I'm pretty sure I'm missing something. (Maybe there is already a library doing the conversion the way I want it to do, but... couldn't find any) #include <stdio.h> #in...