Hi all,
I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects.
Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.
fgets doesn't help either as I still...
What books and environments would you recommend for a person not new to programming but new to C?
...
I read that atoi is deprecated and that it is equivalent to:
(int)strtol(token_start, (char **)NULL, 10);
does that mean I should use the above instead of atoi(chr) or is it just saying they are equivalent?
...
I am trying to write a code, where name of functions are dependent on the value of a certain macro variable. To be specific, I am trying to write a macro like this:
#define VARIABLE 3
#define NAME(fun) fun ## _ ## VARIABLE
int NAME(some_function)(int a);
Unfortunately, the macro NAME() turns that into
int some_function_VARIABLE(int ...
I read that the order of bit fields within a struct is platform specific. What about if I use different compiler-specific packing options, will this guarantee data is stored in the proper order as they are written? For example:
struct Message
{
unsigned int version : 3;
unsigned int type : 1;
unsigned int id : 5;
unsigned int ...
I have N threads and they have to do job on shared data.
I am using following structure:
int main(){
pthread_create(..., func, ...);
}
void *func(void *id){
lock;
do_job;
unlock;
}
My problem is that threads seem to work sequentially. How to actually make them parallel?
...
Consider the C program composed of two files,
f1.c:
int x;
f2.c:
int x=2;
My reading of paragraph 6.9.2 of the C99 standard is that this program should be rejected. In my interpretation of 6.9.2, variable x is tentatively defined in f1.c, but this tentative definition becomes an actual definition at the end of the translation unit...
Im taking C programming at class and Im doing practice questions in the book.
One of the questions is "Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $20, $10, $5, %1 bills:
The sample is as follows, then what I came up with, followed by my dilemna. Yo...
Is there any software or library available to draw screws in 3 dimensions in C, C++, Java, or Ruby?
...
what would the recursive version for the following function would be like:
void tri_loop(size_t i, size_t j, size_t k)
{
for(size_t x = 0; x < i; ++x)
for(size_t y = 0; y < j; ++y)
for(size_t z = 0; z < k; ++z)
{
cout << x <<y << z;
}
}
Just for mental drilling.(Edit: emp...
We're sniffing packets using libpcap on linux
The header we get on each packet looks like:
struct pcap_pkthdr {
struct timeval ts; /* time stamp */
bpf_u_int32 caplen; /* length of portion present */
bpf_u_int32 len; /* length this packet (off wire) */
};
Now, It is my understanding that caplen ...
Hi,
I wanted to know Why code segment is common for different instances of same program.
For Eg: Consider program P1.exe running, if another copy of P1.exe is running, code segment will be common for both running instances. Why is it so ?.
Answer will be highly appreciated.
Thanks in advance.
...
I need to sort a doubly-linked list. According to the almighty wikipedia, mergesort is the way to go for that.
The recursive algorithm works reasonably well, but as I'm writing a general-purpose implementation, performance might be an issue.
Porting the iterative version for arrays will kill performance as rescanning the list to divide...
I have zillions of my_printf() function calls in a huge program. I now want to convert them all so that the function takes a new integer argument (call it x) without having to edit the zillions of calls. If my_printf only ever took exactly one string argument then I could do something like this:
#define my_printf(str) _my_printf(x,s...
hi
i want to know how i can write php function in c (like strtoupper). if is there any tutorial please put it here
thanks
...
I have a function that needs quite some internal temporary storage for its computations (some matrix operations) and I know that this function will be called frequently (say every millisecond throughout the runtime of the program). My gut feeling tells me that it's better to declare those temporary variables static, so there's not so muc...
I am trying to write a wrapper function to figure out who is calling a specific function. So in .h file I added the following: (and implementation in the .cc file)
extern int foo(/*some arguments*/);
extern void call_log(const char*file,const char*function,const int line,const char*args);
#define foo(...) (call_log(__FILE__, __FUNCTI...
I was expecting this to print a very large number and that same number -1 but it just prints -1 and -2, why is this?
fprintf(stderr, "%d\n", 0xffffffff);
fprintf(stderr, "%d\n", 0xfffffffe);
...
Hi
Just wonder, for a matrix stored in a file as what it is, i.e. each line in the file being a row of the matrix where elements are separated by space(s), how can I predetermine the size of the matrix, then create an array of the same size and read it into the array in C and C++? If you have some code example, that would be appreciated...
We want to use CUnit to test a shared library that we have developed.
The shared library is loaded via the standard Solaris LD_PRELOAD mechanism where it uses an environment variable to remap a string containing a file path to a new date and time based on the file path.
Initial testing will use a single value for the environment variab...