The following code does not yield the answer I expect when I multiple a float * 12.
void setup_timer_parameters(float micro_seconds)
{
//constants
calibration = 0;
//calculables
periods_needed = micro_seconds * 12 + calibration;
target_overflows = periods_needed / 65536;
overflows_counter = target_overflows;
temp...
I am taking command line arguments to main from parent to child and counting them and printing. My question is that i am not sure that i am reaping the child? dont i just need an exit 0
or do i need to call fork again?
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int argc...
I was fooling around with one of the sample programs in the K&R, and found that this
#include <stdio.h>
main()
{
double nc;
for (nc = 0; getchar() != EOF; ++nc)
;
printf("%lf\n", nc );
putchar(nc);
}
produces output that is 3.000000 (which I totally expected) then a new line with a heart on it (which I totall...
I am working on an assignment for networking where we are supposed to create a networking library in C and then use it in our C++ program. My C++ isn't as strong as my C so I got started on that first so I could tackle any problems that came up, and I present you my first one. :D
I have a base class and an inherited class (there will ev...
Hi,
I'm looking for a way to atomically increment a short, and then return that value. I need to do this both in kernel mode and in user mode, so it's in C, under Linux, on Intel 32bit architecture. Unfortunately, due to speed requirements, a mutex lock isn't going to be a good option.
Is there any other way to do this? At this point, ...
My current problem is that I have several enemies share the same A.I. script, and one other object that does something different. The function in the script is called AILogic. I want these enemies to move independently, but this is proving to be an issue. Here is what I've tried.
1) Calling dofile in the enemy's constructor, and then ca...
Is it just to test compile a simple program, with that header file #included in it?
To better understand the compilation process I'm writing my own "configure", which tests for the existence of a few header and library files.
...
for C, is there a function that takes an int and doesn't execute next statement ?
printf("a");
wait(500);
printf("b");
b will be printed after 500ms after a is printed out. something of the sort. sorry for the stupid question but i wasn't sure how to go about searching for such function.
...
Hello,
I have built a plain C code on Linux (Fedora) using code-sorcery tool-chain. This is for ARM Cortex-A8 target. This code is running on a Cortex A8 board, running embedded Linux.
When I run this code for some test case, which does dynamic memory allocation (malloc) for some large size (10MB), it crashes after some time giving err...
Hello,
I want to get a HTML and use like a file in C. Actually I can do that, but I have to save the file first on the disk and then use fopen("/file.html", "r");. What I would like to do is to extract the html directly from the URL and work with it.
Hypothetically, fopen("http://www.google.com", "r");
I saw something about libcurl bu...
I've been working through potential interview questions and one of them was to write a function in C to detect whether a given string was a palindrome or not.
I've gotten a pretty good start on it:
#include <stdio.h>
#include <stdbool.h>
bool isPalindrome(char *value);
bool isPalindrome(char *value)
{
if (value == null)
r...
EDIT: the code below has been fixed to receive and send properly AND to account for the actual bytes of messages sent annd recieved (latter thanks to EJP)
Hey guys, I'm programming in C, Unix.
I have server and client that are supposed to exchange msgs. While client seems to send messages fine, server doesn't receive the messages the c...
I have an array of unsigned integers in C and a java array of longs. I want to copy the contents of the unsigned integers to the java array. So far, the only function that I've found to do this is SetLongArrayRegion(), but this takes an entire buffer array. Is there a function to set only the individual elements of the java array?
Th...
I recently discover the LLVM (low level virtual machine) project, and from what I have heard It can be used to performed static analysis on a source code. I would like to know if it is possible to extract the different function call through function pointer (find the caller function and the callee function) in a program.
I could find th...
I'm using both Linux and Win32 socket APIs. In my program, multiple threads share a socket handle. In particular, multiple threads call send with the shared socket handle (i.e., the same port). In this case, do I have to put a lock for thread safety? I was unable to find the answer. I may do a test, but want to hear your experiences.
ED...
Possible Duplicate:
Why does tm_sec range from 0-60 instead of 0-59 in time.h?
So when I looked up <time.h> for some info, I ran across this. I'm assuming the numbers in the square brackets are the ranges possible for each respective member of the structure. So why is there 0~61 possible range for seconds? Were there 62 second...
What happens inside memory if we try to free a pointer which is pointing to NULL?
Is that ever valid?
Why does it not show any warning/error messages?
...
With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this function takes vararg parameters that are printf format specifiers.
This is very helpful in the cases where I wrap e.g. the vsprintf function family. I can have
extern void log_error(const char *format, ...) __attribute__((format(printf, 1, ...
Hi!
I am trying to control ftp client from C program (OS X). I did fork and execve - process is started ok. The problem is with pipes - I can send command to ftp client process and get feedback from it just fine (If i send "help\n" i get back help output) but what I never get in pipe is "ftp> " prompt. Any ideas?
Ivan
...
Sometimes I see code like this (I hope I remember it correctly):
typedef struct st {
int a; char b;
} *stp;
While the usual pattern that I familiar with, is:
typedef struct st {
int a; char b;
} st;
So what's the advantage in the first code example?
...