c

How to iterate over a string in c?

Right now I'm trying this: #include <stdio.h> int main(int argc, char *argv[]){ if (argc != 3){ printf("Usage: %s %s sourcecode input", argv[0], argv[1]); } else { char source[] = "This is an example."; int i; for (i = 0; i < sizeof(source); i++){ printf("%c", source[i]); ...

Need help tracking down USB error

Currently I have an objective-C program that detects when a Fujitsu scanner is added and removed from the computer. I'm trying to add the ability to ask the scanner information about itself. I know the command for this, however, something is going wrong. I'm doing a bit of cargo-cult programming, from two different cargo cults (How do yo...

How can my C/C++ application determine if the root user is executing the command?

Hello, I am writing an application that requires root user privileges to execute. If executed by a non root user, it exits and terminates with a perror message such as: pthread_getschedparam: Operation not permitted I would like to make the application more user friendly. As part of its early initialization I would like it to che...

Traverse tree without recursion and stack in C

How to traverse each node of a tree efficiently without recursion in C (no C++)? Suppose I have the following node structure of that tree: struct Node { struct Node* next; /* sibling node linked list */ struct Node* parent; /* parent of current node */ struct Node* child; /* first child node */ } It's not ho...

While performing operations will the bookid's get changed?

I have made a program which is a small library operated via software. When I add two books and then delete the first book the second book gets the same bookid as the first book because of count-- in the del() function. I cannot rely on printing the count as the bookid. Is there a better option? #include<stdio.h> #include<conio.h> #inclu...

How does a macro-enabled language keep track of the source code for debugging?

This is a more theoretical question about macros (I think). I know macros take source code and produce object code without evaluating it, enabling programmers to create more versatile syntactic structures. If I had to classify these two macro systems, I'd say there was the "C style" macro and the "Lisp style" macro. It seems that debu...

Output into file and command line

Hi there, I read about freopen to redirect all printf to a file, but I would like the output to be printed on the screen as well. Is there an easy way to redirect the printfs to a file and get the cmd line output? Thanks! ...

Variable length space using printf

I'm trying to format some printf statements to allow for arbitrary levels of indentation. Ideally I want the following output where "One", "Two", etc are placeholders for variable length log messages. One Two Three Two One I'm working on the variable length spacing required for the indentation, and I know I can do the following: ...

Non-Integer numbers in an String and using atoi

If there are non-number characters in a string and you call atoi [I'm assuming wtoi will do the same]. How will atoi treat the string? Lets say for an example I have the following strings: "20234543" "232B" "B" I'm sure that 1 will return the integer 20234543. What I'm curious is if 2 will return "232." [Thats what I need to solve ...

function like Macro define

I'd like to define a function like MACRO . i.e. #define foo(x)\ #if x>32\ x\ #else\ (2*x)\ #endif that is, if x>32, then foo(x) present x else, foo(x) present (2*x) but my GCC complains about: int a = foo(31); I think C preprocessor should be handle this correctly. since at compile time, it knows x=33. it could replace foo(33...

hash function for src dest ip + port

So, I am looking at different hash functions to use for hashing a 4 tuple ip and port to identify flows. One I came across was ((size_t)(key.src.s_addr) * 59) ^ ((size_t)(key.dst.s_addr)) ^ ((size_t)(key.sport) << 16) ^ ((size_t)(key.dport)) ^ ((size_t)(key.proto)); Now for the world of me, I cannot expla...

How do you print the EXACT value of a floating point number?

First of all, this is not a floating point newbie question. I know results of floating point arithmetic (not to mention transcendental functions) usually cannot be represented exactly, and that most terminating decimals cannot be represented exactly as binary floating point numbers. That said, each possible floating point value correspo...

About single row query results with parameterized querying

Soo, I'm having a few places in my program where I just fetch a single row (sometimes even a single column in a single row), for example SELECT id,title,posted FROM posts WHERE id=4; Since this will only return a single row (unless I suck at database stuff and somehow manage to have duplicated IDs) I feel it's overkill to go the whole...

Video capture filter

How I can filter video stream from camera in MacOS X. I write quicktime sequence grabber channel component, but it`s work only if app used SG API. If app used QTKit Capture the component is not worked. Somebody know how I can implement it? ...

Starting with the Core Audio framework

For a project that I intend to start on soon, I will need to play back compressed and uncompressed audio files. To do that, I intend to use the Core Audio framework. However, I have no prior experience in audio programming, and I'm really not sure where to start. Are there any beginner level resources or sample projects that can demonstr...

How to get the position/dimensions of the open context menu on the desktop?

Hi, I have a utility that is opened from the context menu. You right-click an item in Windows Explorer and hit the "utility" button in the context menu to open the app. This brings up a little 'window' that's styled to be similar to a right click menu. Currently, it's really jarring to have that new menu open in a completely different p...

C - fork - wait problem

I wrote this code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <sys/shm.h> #define N 512 void chunk0(unsigned int *s, unsigned int *a, unsigned int *b, int MID,int it); void chunk1(unsigned int *s, unsigned int *a, unsigned int *b, int MID,int it); void chunk2(unsigned int *s, unsig...

after half of the program it turns like a palindrome

i made the strrev function myself.while compling it says that the code in the func xstrrev() has no effect.i would also like to know that while making a copy of the built in funtion for assignments can we use builtinfunctions(other) in it?as i used strlen() in it. #include<stdio.h> #include<conio.h> #include<string.h> void xstrrev(char ...

cant convert lowercase to uppercase a string by preprocessor directive

i made a program which converts lower case to upper case a string.i know how to convert a char to upper case via preprocessor directives but i dont know how to do it for a string. #include<stdio.h> #include<conio.h> #include<ctype.h> #define UPPER([]) ([]-32) void fstring_convert(char string[]); void main(void) { char string[40]; print...

What is the difference between macro constants and constant variables in C?

Possible Duplicate: static const vs #define in c I started to learn C in these days. And couldn't understand clearly differences between macros and constant variables. What changes when I write, #define A 8 and const int A = 8 ? ...