I have the following two structs where "child struct" has a "rusage struct" as an element.
Then I create two structs of type "child" let's call them childA and childB
How do I copy just the rusage struct from childA to childB?
typedef struct{
int numb;
char *name;
pid_t pid;
long userT;
...
I have been playing around with the stack on a Ubuntu 9.04 system running gcc 4.3.3 with the randomize_va_space kernel variable set to 0(/proc/sys/kernel/randomize_va_space)
If I declare an auto variable in a function which is an array with its size being determined by the input then how is the array allocated on the stack?
The functio...
how to add a member variable/attribute to a structure from main in C?
...
I have been playing with libpcap/jpcap. Implementing a arp sweeper. I send a request for all ip's in the block to the broadcast address and read replies. Now i can't think of a way to exit from the listening function. Now i wait 2 secs and assume ever client responded but this just seems dirty. Can anyone recommend a logic to determine i...
Is it safe to return the pointer to a local struct in C? I mean is doing this
struct myStruct* GetStruct()
{
struct myStruct *str = (struct myStruct*)malloc(sizeof(struct myStruct));
//initialize struct members here
return str;
}
safe?
Thanks.
...
I have a game that uses layers as a way to organize depth. It works fine but I have stumbled into a silly problem...and despite being simple I can't get it to work EXACTLY as I need.
The idea is that once a graphic is completely out of the game area (as it its right side has completely traveled through the area's left side, so it's not v...
I started to learn how to program when I was 8 years old with BASIC. After like 5 years of GW-BASIC, I started to program in C and inline assembly language with my IBM XT PC. In my high school days, I used to program in C++, but it was rather close to C. And then since I entered university and until now (10 years), I have been using J...
gcc complains about this:
#include <stdio.h>
static const int YY = 1024;
extern int main(int argc, char*argv[])
{
static char x[YY];
}
$ gcc -c test1.c
test1.c: In function main':
test1.c:5: error: storage size of x' isn't constant
test1.c:5: error: size of variable `x' is too large
Remove the “static” from the definition of x an...
I develop with XCode 3.2 under Snow Leopard, and I want to read a jpg-file from disk into memory and manipulate directly with the raw image bitmap presented as a C char array. How can I achieve this?
...
Does anyone have a reference to a poster/one-page pdf or something similar with a list of the eight phases of translation for the C language (the first one being trigraph translation)? I want to have one printed hanging on my wall next to my pc.
Update: Sorry for forgetting to specify. I am interested in C90 (although C99 probably is pr...
Hi, i'm developing a video server in C on GNU/Linux, and i'm using ffmpeg to manage data of each video file. So, i open the file, get all the information about its container, then do the same with its codec and start reading frames one by one.
Unfortunately, ffmpeg and more precisely avcodec is not very well documented. I need to know w...
If i have char* str; how do I write a function that accepts str and can make changes to str so that, the changes persist after the function returns?
what I have is:
char *str = (char *) malloc(10);
sprintf(str, "%s", "123456789");
//str points to 1
move_ptr(&str);
//str points to 2
void move_ptr(char** str)
{
*str++;
}
is there ...
char *str = malloc (14);
sprintf(str, "%s", "one|two|three");
char *token1, *token2, *token3;
char *start = str;
token1 = str;
char *end = strchr (str, '|');
str = end + 1;
end = '\0';
token2 = str;
end = strchr (str, '|');
str = end + 1;
end = '\0';
...
free(start);
does that free work properly since I have been setting bytes wit...
I want to find the fastest way to get the index of the lowest order bit of a long long. ie:
00101001001000 -> 3
Solutions involving looping and shifting are too slow. ie:
int i;
if(bits == 0ULL) {
i = 64;
} else {
for(i = 0;!(bits & 1ULL);i++)
bits >>= 1;
}
EDIT: Info on usage
The function that uses ffsll can't really re...
So, I'm a bit stymied. According to man 3 printf on my system, the string format "%5s" should use the specified precision to limit the number of characters printed from the string argument given.
% man 3 printf
PRINTF(3) BSD Library Functions Manual PRINTF(3)
NAME
printf, fprintf, sprintf, snprintf,...
Trying to write out a simple C Calculator script, using only the basic +, -, /, *. I have the following but not sure why it's not printing correctly. Any experienced C users out there?
#include<stdio.h>
#include<stdlib.h>
int main (void)
{
//introduce vars
double number1, number2, result;
char symbol; //the operator *, -, ...
Hi,
I have this function which is called about 1000 times from main(). When i initialize a pointer in this function using malloc(), seg fault occurs, possibly because i did not free() it before leaving the function. Now, I tried free()ing the pointer before returning to main, but its of no use, eventually a seg fault occurs.
The above...
how do cross platform frameworks like sdl or java provide platform independed keycodes. do they have mapping tables for all possible cases? or is there another (eventually better) way to achieve this.
i need this because i am working on an open source framework for (continuous) dynamic keystroke authentication. i have clients int the fo...
Is there an easy way to call a C script to see if the user inputs a letter from the English alphabet? I'm thinking something like this:
if (variable == a - z) {printf("You entered a letter! You must enter a number!");} else (//do something}
I want to check to make sure the user does not enter a letter, but enters a number instead. Won...
I am so confused with Modulus in C. I am writing a small script that allows the user to input their two number vars, then they can either add, subtract, multiply, divide (easy) or modulus (haven't caught this one yet). What would I be doing wrong in this? I get the "invalid operands to binary %" error, which means I need to format it to ...