c

how to pass int/char into system() a Linux system call

Ok it might sounds dumb, but I couldn't figure out a way to pass int/char into this system call here is how I would like it to work system ("cal %d %d", month, year); I expect this will give me the following command on terminal "cal 3 2009" and the terminal will show me the calendar of March 2009. But the compiler is complaining ...

Flow controlling macros with 'goto'

Yes, two hated constructs combined. Is it as bad as it sounds or can it be seen as a good way to control usage of goto and also provide a reasonable cleanup strategy? At work we had a discussion about whether or not to allow goto in our coding standard. In general nobody wanted to allow free usage of goto but some were positive about us...

How to get ip address programactically on Debian based system?

I'm trying to retrieve the ip address of the local machine in my program. The OS running is Ubuntu 8.10. I tried using gethostname() and gethostbyname to do it. All I can get is 127.0.1.1. I learned that it seems to be a Debian thing: This thread explained it. The content of my /etc/hosts file is also: 127.0.0.1 localhost 127.0.1.1 mymac...

Is there an un-buffered I/O in Windows system?

I want to find low-level C/C++ APIs, equivalent with "write" in linux systems, that don't have a buffer. Is there one? The buffered I/O such as fread, fwrite are not what I wanted. ...

Getting the current hour in C using time.h

Total newbie question here; I apologize in advance. Suppose I have a daemon written in C that wakes itself up every five minutes or so, does some processing if there's anything in its input queue, and then goes back to sleep. Now suppose there is some processing that it only has to do after a certain (configurable) time--say, 2 pm (and ...

iPhone Cocoa mixed Mode Math Basic Errors

Just realized that I am getting errors on simple math if I mixed Integer with floats in iPhone SDK on the Simulator. Two examples: float testVal1 = 10 + 5/10; //evaluates to 10 instead of 10.5 unless I use explicit 10.0f.. // Problem Code mixed float int NSUInteger jvalue = 2312345; NSInteger testVal2 = (jvalue - 2512345); // evalua...

How to get memory locations of library functions?

I am compiling a C program with the SPARC RTEMS C compiler. Using the Xlinker -M option, I am able to get a large memory map with a lot of things I don't recognize. I have also tried using the RCC nm utility, which returns a slightly more readable symbol table. I assume that the location given by this utility for, say, printf, is the l...

Rewriting C++ methods in C

How can I make equivalents to these methods in C? I read somewhere that they could be "replaced with functions that take a structure pointer as the first parameter," but I'm not sure how to do this, if that is the right thing to do. struct SCustomKeys { struct SCustomKey Save[10]; struct SCustomKey Load[10]; struct SCustomK...

How can I make an AJAX server side script in C?

I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C? Will the C application just use printf for the data, similar to this .asp example? ...

How do I get sender's UDP port in C ?

I have the following typical code in C under Linux to get UDP data: sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); mysock.sin_family = AF_INET; mysock.sin_addr.s_addr = INADDR_ANY; mysock.sin_port = my_port; bind(sock, &mysock, sizeof(mysock); recvfrom(sock, buf, PKTSZ, 0, &client, len); All the above code works, but now I have a ne...

need hint with a custom Linux/UNIX command line utlity "cal" in C

Ok I need to make this program to display "cal" 3 month(one month before and one month after) side by side, rather than just one single month it displays in any Linux/UNIX. I got it working to display 3 calendar by using "system(customCommand)" three times; but then it's not side by side. I got some hint to use the following system cal...

question about incompatible printf format specifiers

I was just looking through the man page for printf and something occurred to me. I was wondering if there are any "language lawyers" here which could answer a relatively simple question :-P. So the 't' modifier is defined as A following integer conversion corresponds to a ptrdiff_t argument. So what is supposed to happen if you...

What's the easiest way to display an image in C/Linux?

I'm quite comfortable with C for numerical computation, but not for graphical programming. I have a Nx by Ny by 3 RGB matrix in a command-line program for linux (gcc, ubuntu) and I want to pop up a window with it as an image. What's the easiest way to do this? It has to be relatively quick because I'll be updating the image frequently....

Help me convert my Lisp code to a C-based syntax

If you know LISP, could you please change this into C-based sytnax for me (ie. C/C++/C#/Java ..etc)? (let ((g (* 2 (or (gethash word good) 0))) (b (or (gethash word bad) 0))) (unless (< (+ g b) 5) (max .01 (min .99 (float (/ (min 1 (/ b nbad)) (+ (min 1 (/ g ngood)) ...

using unput wrong

I created test.l, input to flex, which ends with the main function. When the main function is implemented as: int main(void) { yylex(); return 0; } I have no problem. I want to trick the parser into believing that the first character is always a semi-colon, so I implemented main as int main(void) { unput(';'); yylex(...

What data structure is behind FD_SET and FD_ISSET when working with sockets in c?

What data structure is behind FD_SET and FD_ISSET macro when working with sockets? ...

Catching return codes in production environments?

Hi All, I want to know if check for return codes for all of functions that we write for production environment. for e,g, i use C a lot and do u catch the return codes for the standard library also, not just the functions that you write , but the 3rd party API/standard library/any other library. Most code i see in production do not do t...

Is there a way to make a function atomic in C?

Is there a way to make a function atomic in C. I am not looking for a portable solution.(platforms looking for - Win,Linux) ...

How to traverse a trie longitudinally?

Hello, i have a Trie and several functions modifiing it. typedef struct node *pnode; typedef struct node { int element; pnode next;//same level, other element pnode subtree;//next level } node; Now, in order to debug and/or test my functions, I need to print out the tries. I tried it recursively, but I cannot get the fi...

How to multiply a given number by 2 without using arithmetic operators in c?

How to multiply a given number by 2 without using arithmetic operators in c language? ...