In traditional embedded programming, we will give a delay function like so:
for(i=0;i<255;i++)
for(j=0;j<255;j++);
In the microprocessor's view, is this how the sleep() function works?
Is there an alternative for the sleep() function in C?
...
let us have a situation in which the following program prints some 10 lines of #
for(i=0;i<10;i++)
prinf("\n#");
now how to go back to 5 th line and edit that # and change the color of it without clearing the screen or clearing the below 5 lines?
I have tried
window(5,0,20,20);
textcolor(GREEN);
cprintf("#");
but it is not editing...
I am using BSD style pty/tty pairs to implement running a sub shell. When the user exits the sub shell, how do I detect in the master process that this has occurred? I am using select(nfds, &read_fds, NULL, NULL, &timeout); with the master pty file descriptor set in the read_fds on the master side.
...
Hi,
getopt() is not behaving as I expect for short options.
eg: Invoking the below program with a missing parameter:
Valid Case: testopt -d dir -a action -b build
Error Case: testopt -d -a action -b build
This did not throw any error as I was expecting an error message operand missing for -d
Is this a known bug. If so is there any ...
Is there a standard posix C function to convert encodings, say from windows-1251 to utf-8 and back?
...
A fairly basic question, but I don't see it asked anywhere.
Let's say we have a global struct (in C) like so:
struct foo {
int written_frequently1;
int read_only;
int written_frequently2;
};
It seems clear to me that if we have lots of threads reading and writing, we need a semaphore (or other lock) on the written_frequently me...
I'm using Strawberry Perl which includes MinGW's GCC, I'm also making use of the GNU debugger GDB and Subversion. How can I have a single development environment that would suit this (other than just UltraEdit, the command shell and IE), and how can I further enhance its features?
...
I have been trying to tokenize a string using SPACE as delimiter but it doesn't work. Does any one have suggestion on why it doesn't work?
Edit: tokenizing using:
strtok(string, " ");
the code is like the following
pch = strtok (str," ");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ");
}
...
Hi folks,
Is there a way to define a macro that may contain #include
directive in its body. If I just put
the "#include", it gives error C2162: "expected macro formal
parameter" since here I am not using # to concatenate strings.
If I use "# include", then I receive the following two errors:
error C2017: illegal escape sequence
err...
I always try to avoid to return string literals, because I fear they aren't defined outside of the function. But I'm not sure if this is the case. Let's take, for example, this function:
const char *
return_a_string(void)
{
return "blah";
}
Is this correct code? It does work for me, but maybe it only works for my compiler (gcc). ...
Are there any good source-code analyses tools for OSX. I am particularly interested in tools that are capable of diagramming function-call hierarchies for C and C++ source files.
...
I would like to implement a telnet server in C. How would I proceed with this? Which RFCs should I look at? This is important to me, and I would appreciate any help.
...
When we perform a fork in Unix, open file handles are inherited, and if we don't need to use them we should close them. However, when we use libraries, file handles may be opened for which we do not have access to the handle. How do we check for these open file handles?
...
Hey, in the Programming Pearls book, there is a source code for setting, clearing and testing a bit of the given index in an array of ints that is actually a set representation.
The code is the following:
#include<stdio.h>
#define BITSPERWORD 32
#define SHIFT 5
#define MASK 0x1F
#define N 10000000
int a[1+ N/BITSPERWORD];
void set(in...
I'm working on a code base in which we have several configurable types. One of those types is 64 bit integer. When we compile for platforms that have no native 64 bit integer type, we simple represent 64 bit integers using a struct similar to
typedef struct {
unsigned int hi, lo;
} int64;
In order to make this type useful, all com...
I have a written a Visual C++ console application (i.e. subsystem:console) that prints useful diagnositic messages to the console.
However, I would like to keep the application minimized most of the time, and instead of minimizing to the taskbar, appear as a nice icon on the system tray. I would also like to restore the console when the...
How can I make ctrl k,d work in a pure C file?
I really enjoy the auto formatting in C#, and I would like to have the same functionality in C as well.
I am using VS2008, but it would probably be helpful if this worked in VS2005 as well.
...
I am trying to write an interface between RSPEC (ruby flavoured BDD) and a Windows application. The application itself is written in an obscure language, but it has a C API to provide access. I've gone with Ruby/DL but am having difficulties getting even the most basic call to a DLL method to work. Here is what I have so far, in a fil...
On Linux (or Solaris) is there a better way than hand parsing /proc/self/maps repeatedly to figure out whether or not you can read, write or execute whatever is stored at one or more addresses in memory?
For instance, in Windows you have VirtualQuery.
In Linux, I can mprotect to change those values, but I can't read them back.
Furthe...
On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like.
Is there a similar equivalent I can use on the GCC compi...