Hello all,
I'm trying to extract the parameter with which an app was called by using the data inside cmdline.
If I start an application instance like this:
myapp 1 2
and then cat the cmdline of myapp I will see something like myapp12.
I needed to extract these values and I used this piece of code to do it
pid_t proc_id = get...
Is there a way to retrieve path information from a file descriptor or FILE pointer?
I'm aware that this data may not always be relevant/useful for case where the file descriptor is a socket, pipe, etc.
...
Right now I've got a simple TCP server/client. I have it set up so that whenever a client connects it gets forked() and the connection itself is put into an infinite loop so that the connection stays open. The server is receiving information from the client, I have a check to make sure that the number of bytes received is > 0. That has b...
Hi I have the following program. When I compile on the terminal gcc main.c I do get an executable named a.out. However if I type a.out in the terminal I get the following message: a.out: command not found
Any ideas on what I might be doing wrong?
#include <stdio.h>
#include <stdlib.h>
#define PROMPT "print something"
/*
*
*/
int m...
I need to read the input from the console and put it into an array of chars. I wrote the following code, but I get the following error: "Segmentation Fault"
#include <stdio.h>
#include <stdlib.h>
int main() {
char c;
int count;
char arr[50];
c = getchar();
count = 0;
while(c != EOF){
arr[count] = c;
...
I'm sort of learning C, I'm not a beginner to programming though, I "know" Java and python, and by the way I'm on a mac (leopard).
Firstly,
1: could someone explain when to use a pointer and when not to?
2:
char *fun = malloc(sizeof(char) * 4);
or
char fun[4];
or
char *fun = "fun";
And then all but the last would set indexes 0...
I have developed a interpreted programming language. It is strongly based on C. The problem is, I want to add a foreach directive and have no clue how to.
I am using Bison and Flex as the parser and lexer generator.
...
Hi, I'm writing a small program in C that will read input from the console. Then put it into a char array. After that I need to split the array into words. I'm not sure how to do this. So far I have put the input into a char array. I need to know if there is a way to tokenize based on a blank character. Or any other suggestions on how ...
I am attempting a multiple producer/consumer problem in C, but its not working as expected. The following is some pseudo code to represent my implementation.
Thread thread1;
Thread thread2;
Thread thread3;
Data data1;
Mutex data1_mutex;
Semaphore data1_empty;
Semaphore data1_fill;
Data data2;
Mutex data2_mutex;
Semaphore data2_empty;
...
hi,
I was programming in C ,... but some months ago I start learning .Net
the C programming lang is not easy ,
That's why I need reference of all reference and explanation of all C standard function
...
Is this legal and/or good practice?
#define SOFTWARE_VERSION_NUMBER "7.0v1.1"
Want struct to always contain the version number.
typedef struct {
char SOFTWARE_VERSION_NUMBER;
int a;
int b;
int c;
}mystruct;
...
In certain areas of development such as game development, real time systems, etc., it is important to have a fast and optimized program. On the other side, modern compilers do a lot of optimization already and optimizing in Assembly can be time consuming in a world where deadlines are a factor to take into consideration.
Questions:
I...
I've two programs I'm using in this way:
$ c_program | python_program.py
c_program prints something using printf() and python_program.py reads using sys.stdin.readline()
I'd like to make the python_program.py process c_program's output as it prints, immediately, so that it can print its own current output. Unfortunately python_prog...
Does anybody know where I can find a utility/application running on Windows that analyses C source and outputs a functional dependency tree?
What I'm looking for is something along these lines:
PrintString->PrintCharacter->PrintByte->Printf
...
The title pretty much says it all, do you prefer to see something like t_byte* (where t_byte would be a typedef for unsigned char) or unsigned char* in code? I'm leaning towards t_byte in my own libraries, but have never worked on a large project where this approach was taken, and am wondering about pitfalls.
Regards,
Dan O.
...
Hi,
I have 10 processes running, each writing to the same file. I don't want multiple writers, so basically I am looking for a mutex/binary semaphore to protect file writes. The problem is I can't share the semaphore amongst 10 processes, so I am looking at using shared memory between 10 processes, and putting the semaphore inside share...
Hi,
I once saw a programming pattern (not design), how to implement a fast copy of buffers. It included an interleaved loop and switch. The thing was, it copied 4 bytes most of the time, only the last few bytes of the buffer were copied using smaller datatypes.
Can someone tell me the name of it? It's named after a person. It's done in...
I want to simulate many key press events. I found a solution by using XTestFakeKeyEvent, but when I simulate more than 210 times my program raises a "Maximum number of clients reached" segmentation fault. I don't known how to solve this problem.
My code here:
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest....
Imagine the following:
you read in a string with scanf() but you only need a few of the datapoints in the string.
Is there an easy way to throw away the extraneous information, without losing the ability to check if the appropriate data is there so you can still reject malformed strings easily?
example:
const char* store = "Get: 15 b...
Hi -
I am rolling my own exception library for C and would like good examples to examine.
So far, I have been looking at David Hanson's:
http://drhanson.net/work/
But I know I've seen other ones available in the past. Can you send me some additional pointers?
Thanks,
SetJmp
...