How to flush the stdin??
Why is it not working in the following code snippet?
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include <fcntl.h>
int main()
{
int i=0,j=0, sat;
char arg[256];
char * argq;
argq = malloc(sizeof(char)*10);
printf("Input the line\n");
i=read(0, a...
if I have something like:
long x = 1/2;
shouldn't this be rounded up to 1? When I print it on the screen it say 0.
...
can someone explain to me why the following results in b = 13?
int a, b, c;
a = 1|2|4;
b = 8;
c = 2;
b |= a;
b&= ~c;
...
Does anyone know a way to go from a pthread_t to what GDB displays with info threads?
So I have:
(gdb) info threads
37 Thread 22887 0xb7704422 in __kernel_vsyscall ()
36 Thread 22926 0xb7704422 in __kernel_vsyscall ()
35 Thread 22925 0xb7704422 in __kernel_vsyscall ()
34 Thread 22924 0xb7704422 in __kernel_vsyscall ()
33 ...
I'm working on an embedded project and I'm trying add more structure to some of the code, which use macros to optimize access to registers for USARTs. I'd like to organize preprocessor #define'd register addresses into const structures. If I define the structs as compound literals in a macro and pass them to inline'd functions, gcc has...
I have been cutting my teeth for the past 48 hours or so trying to implement this hash table function in C. My code is rather long (I realize it is not the most efficient, some of it is more me playing around with C to get a feel for how it works etc).
The problem I am having is with the last line of my main program at the bottom (prin...
One of the only languages that compiles to a high level language such as C, Vala has interested me for quite a bit. I've been wanting to start a small project with it, but I've been wondering how I would distribute it.
The fact is, that it compiles to C code (C99 I suppose).
Can I distribute the C code instead
of the Vala code?
If I ...
in the example:
#include <stdio.h>
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
I don't quite understand it. putchar() would put the character out, but why is it that after EOF it puts all the characters out, and where is it remembering all these characters? Thanks.
...
If I have:
const char *mystr = "cheesecakes";
FILE *myfile = fopen("path/to/file.exe","r");
I need to write a function to determine whether myfile contains any occurrences of mystr. Could anyone help me? Thanks!
UPDATE: So it turns out the platform I need to deploy to doesn't have memstr. Does anyone know of a free implementation I c...
I have something like this:
#define QUIT_TIME 5
int main(int argc, char **argv) {
//... SOCKETS STUFF ....
fdmax = parentfd;
while (notdone) {
//Set the timers
waitd.tv_sec = 1;
waitd.tv_usec = 0;
FD_ZERO(&tempreadfds);
FD_ZERO(&tempwritefds);
FD_ZERO(&readfds); ...
Hi everybody! I am trying to learn serial programming using C. Does anyone know where I can find some good examples?
Thank you very much!
...
wcstombs documentation says, it "converts the sequence of wide-character codes to multibyte string". But it never says what is a "wide-character".
Is it implicit, like say it converts utf-16 to utf-8 or the conversion is defined by some environment variable?
Also what is the typical use case of wcstombs?
...
...for use in a multithreaded network server.
I want to pass data around between multiple threads. Currently I'm using sockets, with the master thread blocking on select() and workers blocking on recv(), though I feel there probably are more advanced or prepackaged ways of handling this task in C++.
...
I have one static variable declared inside a function, which is not initialized to zero explicitly.
Are all uninitialized static variables inside functions set to zero by default, just as static variables at the global (file) level are?
...
Hi,
I am basically working on unix and c programming.
i want to start learning Pro*c on unix.
Is there any good online tutorial which will help me start writing simple programs in pro*c and compiling those Pro*c files.?
Thanks in advance for your help.
...
Hello,
I am preparing myself for a lecture exam on security aspects of software development. I would like to know if it is always possible to read the value of a static char array from a binary with hexdump?
If not on what factors does it depend whether I can read the value of it or not with a hexeditor??
thanks,
...
Greetings! I wrote a highly scalable HTTP event (long-polling) server in C/C++ using libevent. However, it's messy, hardly portable, and lets face it: it's C. Let alone that I've been having some major issues with the mysqlcpp connector (which is complete trash), and some minor issues with libevent (it could be because I'm using 2.0.1-al...
Consider the follwoing fragment:
int a,b;
a = 1;
b = 2;
c = a++++b; // does not work!! Compilation error.
c = a++*+b; // works !!
Please help me understand this behaviour.
...
Given a linked list of T size , select first 2n nodes and delete first n nodes from them; Then do it for the next 2n nodes and so on...
For example-
Let's consider a linked list of size 7:
`1->2->3->4->5->6->7`
If n = 2, the desired output is :
`1->2->5->6->7`
I didn't understand what this problem is actually indicating.Could...
Thank you guys for answering "capturing commandline output directly in a buffer" .. thanks a lot.. I used popen() to get my results correct.
here i have one more thing may be small one
I need to print something in my window when the script "check.sh" returns nothing, means validation when no output from the script is returned.
check.s...