I was going through one of the threads.
A program crashed because
It had declared an array of 10^6 locally inside a function.
Reason being given was memory allocation failure on stack leads to crash.
when same array was declared globally, it worked well.(memory on heap saved it).
Now for the moment ,Let us suppose,
stack grows downwar...
I am reading some source code and I found at the very begin of the main routine
this statement:
umask(077);
What could be the reason for that?
The man page (man 2 umask) states:
umask -- set file creation mode mask
This clearing allows each user to
restrict the default access to his
files
But is not clear to me why wo...
I have a list of installed software, obtained from WMI class select * from Win32_Product.
I'd like to deny execution rights for some users on certain software like so:
find the path to installed software
recursively remove execution rights
I find the path to installed software from Win32_Product InstallLocation column. But the PROBLE...
stdinBackup = 4;
dup2(0, stdinBackup);
Currently I am doing the above to 'backup' stdin so that it can be restored from backup later after it has been redirected somewhere else. I have a feeling that I am doing a lot wrong? (eg arbitrarily assigning 4 is surely not right). Anyone point me in the right direction?
...
I have an experimental library whose performance I'm trying to measure. To do this, I've written the following:
struct timeval begin;
gettimeofday(&begin, NULL);
{
// Experiment!
}
struct timeval end;
gettimeofday(&end, NULL);
// Print the time it took!
std::cout << "Time: " << 100000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - ...
I am using popen to execute a command under linux, then 4 process wile use the same output.
I am trying to duplicate the file descriptor again to pass it to each process.
here is my code:
FILE* file_source = (FILE*) popen(source_command, "r");
int fd = fileno(file_source);
fdatasync(fd);
int dest_fd[4], y, total = 4;
for (y = 0; y ...
This is too basic I think, but how do both of these work?
return true; // 1
and
return (true); // 2
Similar: sizeof, exit
My guess:
If return was a function, 1 would be
erroneous.
So, return should be a unary
operator that can also take in
brackets... pretty much like unary
minus: -5 and -(5), both are
okay.
...
argv[1]=argv[1]/filenames[j]
argv[1]=folder1
and filenames[2]=cool
I want to store folder1/cool in argv[1]
how to proceed?
I am not familiar with C.
...
Hi all,
I am trying to work with "Introduction to Interprocess Communication Using Named Pipes - Full-Duplex Communication Using Named Pipes", http://developers.sun.com/solaris/articles/named_pipes.html#5 ; in particular fd_server.c (included below for reference)
Here is my info and compile line:
:~$ cat /etc/issue
Ubuntu 10.04 LT...
This is probably a very difficult problem to troubleshoot with the information I can practically provide, but I'm hoping someone might be able to at least point me in a possible direction.
I'm trying to install HTK (http://htk.eng.cam.ac.uk/), which, according to this page needs to be installed using gcc 3.4. Their method of implementin...
I've dumped glyphs from truetype file so I can play with them. They have shape contours that consist from quadratic bezier curves and lines. I want to output triangles for such shapes so I can visualize them for the user.
Traditionally I might use libfreetype or scan-rasterise this kind of contours. But I want to produce extruded 3D mes...
Why does
static char *opcode_str[] = { "DATA"
, "DATA_REQUEST_ACK"
, "ACK_TIMER_EXPIRED"
, "ACK_UNEXPECTED_SEQ"
, "ACK_AS_REQUESTED"
} ;
work, but
static char **opcode_str = { "DATA"
...
I need a function to convert a 32bit or 24bit signed (in two's complement) hexadecimal string into a long int. Needs to work on both 32bit and 64bit machines (regardless of the size of long int) and work regardless of whether the machine is a two's complement machine or not.
SOLUTION:
long int hex2li (char hexStr[], int signedHex)
{
...
How are files downloaded from servers in programming languages like C? I understand higher level languages have magic functions like "download_file_from_url()" but they don't help me understand what is actually going on. I'm a little familiar with sockets but network programming in general is still a black box to me. Thanks for any help....
I'm wondering if there is another way of getting a sub string without allocating memory. To be more specific, I have a string as:
const char *str = "9|0\" 940 Hello";
Currently I'm getting the 940, which is the sub-string I want as,
char *a = strstr(str,"9|0\" ");
char *b = substr(a+5, 0, 3); // gives me the 940
Where substr is my...
Reading through my book Expert C Programming, I came across the chapter on function interpositioning and how it can lead to some serious hard to find bugs if done unintentionally.
The example given in the book is the following:
my_source.c
mktemp() { ... }
main() {
mktemp();
getwd();
}
libc
mktemp(){ ... }
getwd(){ ...; mktemp...
I've got some C code from a 3rd party vendor (for an embedded platform) that uses global variables (for speed & space optimizations). I'm documenting the code, converting to Doxygen format.
How do I put a note in the function documentation that the function requires on global variables and functions?
Doxygen has special commands for...
I want to ask, why I cannot transfer file from server to client?
When I start to send the file from server, the client side program will have problem.
So, I spend some times to check the code,
But I still cannot find out the problem
Can anyone point out the problem for me?
CLIENTFILE.C
#include stdio.h
#include stdlib.h
#include time...
I'm currently using dirent.h and ftw.h for directory traversal at my CGI website 100% programmed in C. I am not sure if they are process safe; would various users interfere with each other while on my site ?
Which functions would you recommend for this purpose ?
...
I cannot use getaddrinfo(...) for resolving hostnames and therefore must stick to gethostbyname(...)
Is the gethostbyname(...) function guaranteed to return hostent structures that contain only IPv4 (AF_INET) addresses on success, so that the following code would always lead to an IPv4 address:
int resolve(const char *name, struct in_a...