OK I have a program that creates two pipes -> forks -> the child's stdin and stdout are redirected to one end of each pipe -> the parent is connected to the other ends of the pipes and tries to read the stream associated with the child's output and print it to the screen (and I will also make it write to the input of the child eventually...
I have this code, it work fin but if i change NUM_CHILDREN = 2 or any other number "not equal 1" it bad file descriptor. why is that?
#include <stdio.h>
#include <unistd.h>
enum {
NUM_CHILDREN = 1
};
static int pipes[NUM_CHILDREN][2];
void start_encoding(void) {
pid_t d, h;
int pipe_master[2];
pipe(pipe_master);
...
Hello,
I'm writing transpose function for 8x16bit vectors with SSE2 intrinsics. Since there are 8 arguments for that function (a matrix of 8x8x16bit size), I can't do anything but pass them by reference. Will that be optimized by the compiler (I mean, will these __m128i objects be passed in registers instead of stack)?
Code snippet:
i...
#include<stdio.h>
#include<math.h>
int main ()
{
FILE *fp;
fp=fopen("output","w");
float t,y=0,x=0,e=5,f=1,w=1;
for (t=0;t<10;t=t+0.01)
{
if( y==inf && y== nan)
break;
fprintf(fp,"%lf\t%lf\n",y,x);
y = y + ((e*(1 - x*x)*y) - x + f*cos(w*t))*t;
x = x + y*t;
}
return...
I want to use dup2 to read from input file and redirect it to the input of exec function. but my problem is i have three running process all of them have to open same input file but they do different jobs. what your suggest in such case? i don't know if it is possible to use "cat data.txt" to feed the input for the three other process bu...
Hi,
Is there any tool to show diagrammatic rep of flow of program if we input a C file?
Thanks.
...
Hi all,
I have a structure defined like so:
typedef struct {
int n;
int *n_p;
void **list_pp;
size_t rec_size;
int n_buffs;
size_t buff_size
} fl_hdr_type;
and in my code I Have a function for initlialization that has the following
fl_hdr_type *fl_hdr;
fl_hdr = malloc(sizeof(fl_hdr_type) + (buff_size_n * rec_size_n));
where ...
I have lockless queues written in C in form of a linked list that contains requests from several threads posted to and handled in a single thread. After a few hours of stress I end up having the last request's next pointer pointing to itself, which creates an endless loop and locks up the handling thread.
The application runs (and fails...
Looking at the information under the heading "Precision can be omitted or be any of:".
The example: printf("%.*s", 3, "abcdef"); works, outputting:abc (truncating the rest of the string.)
Now, I would like to have a string with multiple parameters formatted (truncated):
printf("%.*s, %.*s", 3, 3, "abcdef", "xyz123");
but the progra...
Suppose I have a char* elem that is supposed to hold a char**, such that elem[0] = char**, elem[1...m]= <more chars>. Is there a way I can put a null ptr within char* elem? When I try to set elem = NULL, it gives me a type error because NULL is an int.
Any help would be greatly appreciated!
...
How would I manually concatenate two char arrays without using the strncpy function?
Can I just say char1 + char2?
Or would I have to write a for loop to get individual elements and add them like this:
addchar[0] = char1[0];
addchar[1] = char1[1];
etc
etc
addchar[n] = char2[0];
addchar[n+1] = char2[1];
etc
etc
To clarify, if
char1 =...
Here is what I am working with:
char* qdat[][NUMTBLCOLS];
char** tdat[];
char* ptr_web_data;
// Loop thru each table row of the query result set
for(row_index = 0; row_index < number_rows; row_index++)
{
// Loop thru each column of the query result set and extract the data
for(col_index = 0; col_index < numb...
For the life of me I can't figure out the proper syntax for creating an array of structures in C. I tried this:
struct foo {
int x;
int y;
} foo[][] = {
{
{ 1, 2 },
{ 4, 5 },
{ -1, -1 }
},
{
{ 55, 44 }
{ 100, 200 },
}
};
So for example foo[1][0].x == 100, foo[0][1].y ==...
I was going through an article today when it mentioned the following:
"We've found many errors over the
years. One of the absolute best was
the following in the X Window System:
if(getuid() != 0 && geteuid == 0) {
ErrorF("Only root");
exit(1);
}
It allowed any local user to get root
access. (The ...
Hello, I'm trying to convert some c code to assmebly, and I need some help.
char encode(char plain){
__asm{
mov eax, plain
add eax, 2
ret
}
//C code
/*
char code;
code = plain+2;
return code;*/
}
First problem is that visual studio complains that the register size doesn't matc...
I'm having trouble passing a structure array as a parameter of a function
struct Estructure{
int a;
int b;
};
and a funtion
Begining(Estructure &s1[])
{
//modifi the estructure s1
};
and the main would be something like this
int main()
{
Estructure m[200];
Begining(m);
};
is this valid?
...
What am I doing wrong?
This is the assmebly I've written:
char encode(char plain){
__asm{
mov al, plain
;check for y or z status
cmp al, 'y'
je YorZ
cmp al, 'z'
je YorZ
cmp al, 'Y'
je YorZ
cmp al, 'Z'
je YorZ
;check to make sure it is in the alphabet now
mov cl, al
sub cl, 'A'
...
Having trouble creating my swap chain. I receive the following error.
DX3dApp.obj : error LNK2019: unresolved external symbol _D3D10CreateDeviceAndSwapChain@32 referenced in function "public: bool __thiscall DX3dApp::InitDirect3D(void)" (?InitDirect3D@DX3dApp@@QAE_NXZ)
Below is the code ive done so far.
#include "DX3dApp.h"
bool ...
This probably is one of the easiest question ever in C programming language...
I have the following code:
typedef struct node
{
int data;
struct node * after;
struct node * before;
}node;
struct node head = {10,&head,&head};
Is there a way I can make head to be *head [make it a pointer] and still have the availability to use ...
I am looking for a free static checker for C99 code (including GCC extensions) with the ability to explicitly say "these preprocessor macros are always defined."
I need that last part because I am compiling embedded code for a single target processor. The compiler (Microchip's C32, GCC based) sets a macro based on the selected processo...