Possible Duplicate:
Why doesnt c++ have &&= or ||= for booleans?
I had the need to code a statement of the form
a = a || expr;
where expr should be evaluated and the result be assigned to a iff a is not set. this relies on the logical OR's shortcircuiting capabilities.
The shorter way to write the above would, of course, b...
I wrote this function to read a line from a file:
const char *readLine(FILE *file) {
if (file == NULL) {
printf("Error: file pointer is null.");
exit(1);
}
int maximumLineLength = 128;
char *lineBuffer = (char *)malloc(sizeof(char) * maximumLineLength);
if (lineBuffer == NULL) {
printf("Err...
i want c program for directory monitor
...
I want to set the Don't Fragment flag on a IP packet. Is there a way to do so via the setsockopt() function or via the flags of the sendto() function?
Can I do this with "normal" sockets or do i have to use raw sockets and build the entire IP header myself, setting it's offset-field to IP_DF (which is defined in ip.h)?
...
I have to retrieve process status(whether process is running or stopped) whose procees id is given from my c program(i am using linux). i planned to use exec command
and written below statement
execv("ps -el|grep |awk '{print $2}'",NULL);
But it is not giving me desired output.
Please let me know where i am wrong.
...
A discussion recently ended laughing at the bad habits of programmers that have been too exposed to a language when they start programming in another language. The best example would be a Pascal programmer starting to #define begin { and #define end } when starting to write C.
Goal is to try to catch the bad habits of C programmers when...
Hi, i am using a MYSQL database as form of IPC datastore between web client and C code process on Debian linux. When web client writes some data to the mysql database via php script, i need my C code app to go and pickup that data.
However i don't want the C app continually polling some flag to check if data is available. Is there anywa...
In theory it seems that books sugest declaring ADT in C as:
struct some_structure;
typedef some_structure *some_structure_t;
while most code uses:
struct some_structure;
typedef some_structure some_structure_t;
I know that const is not working with the first style. Is this the only reason for real libraries not to use first approac...
What's happening in this code?
I don't get this code. Looks like it's performing some type of casting or using function pointers but I'm not sure. Will appreciate if someone can help me. Thanks.
const char string[]="Hello!";
int main()
{
(*(void (*)()) string)(); //Obviously, my problem is this line :)
return 0;
}
...
Hi, I've written a rather simple(ish) stack implementation that would automatically grow its internal array buffer if needed.
For that, I'd naturally use realloc - It works, however, all array elements are ordered reverse after the realloc() call.
The code in question:
Header: include/pd/stack.h
Source: src/stack/stack.c
This examp...
The following code causes a SIGSEGV, but only while debugging.
#include <stdio.h>
#include <stdlib.h>
typedef struct enemy_desc
{
int type;
int x;
int y;
}enemy;
int main()
{
enemy **enemies;
enemies=(enemy **)malloc(sizeof(enemy *)*16);
enemies[0]->type=23;
printf("%i",enemies[0]->type);
return 0;
}
...
I quite like being able to generate the same set of pseudo-random data repeatedly, especially with tweaking experimental code. Through observation I would say that rand() seems to give the same sequence of numbers each time*.
Is it guaranteed to do this for repeated executions on the same machine / for different machines / for different...
Hello
In the C/C++ there are 2 types of macro:
#define ABC /* usual */
und
#define FUNC(a) /*function-like*/
But how can I undefine them?
Update: So there is no difference between undefing "constant-like macro" and "function-like macro" ?
...
I have the following program. However, I can't understand why I have to pass the address of the array. When they are both pointing to the same address. Which is the address of the first element of the array of int's.
I get a warning when I try and do this "assignment from incompatible pointer type":
ptr = var;
Complete source code:
...
#include <stdio.h>
#include <string.h>
int main()
{
char s[15];
int i,j,n,*str;
printf("Enter a string");
scanf("%s",str);
n=strlen(str);
for(i=0;i<n;i++)
{
str[n]=str[0];
for(j=0;j<n;j++)
{
str[j]=str[j+1];
}
str[n]='\0';
printf("\n %s",str);
...
I have been programming in python exclusively for 4 years and have never really looked under the hood at the C code in which python is written. I have recently been looking into a problem that would involve modifying python at that level.
The code seems pretty consistent, and thus relatively easily understood. However, it's complex en...
If anyone could please help me out, that would be great :)
This seems to be a tough one. Starting from the process ID, I need to be able to grab:
How much CPU the process is taking up in %
How long the process has been using the CPU
This needs to be written in Cocoa/ Objective-C or C. It also needs to work on Tiger through Snow Leop...
I need to generate time-stamp in this format yyyymmdd. Basically I want to create a filename with current date extension. (for example: log.20100817)
...
Here is my function's code:
char * increment_b_string(char * b_string)
{
char * ret_string = (char *) malloc(7);
ret_string = "001aaa";
if (*(b_string + 2) == '9')
{
*(ret_string +2) == '0';
if (*(b_string + 1) == '9')
{
*(ret_string +1) = '0';
*(ret_string) = *(b_string...
Possible Duplicate:
while (1) Vs. for (;;) Is there a speed difference?
Hi,
Which is better,faster and more optimized way to implement infinite loop - for(;;) or while(1)? and why?
...