I'm working on a MUD in java. I read player input every tick, but I'm using Scanner which uses blocking operations. I want to have non-blocking input. I've looked at the nio package which has a Selector class, but I'm not sure how to use it with regard to System.in. I figure I'll definitely need it once I'm running a server, but for no...
In a program I am developing (Linux), I need very simple text-based IPC. It would be very easy to use a standard input/output pipe for this. Can I trust that messages sent to a process' stdin cannot be read by anyone? Also, can I trust that if I kept the pipe to its stdout, only I can read what it outputs? I just want to make sure there'...
Hi,
I have written a simple twisted application that connects to a server that listens on 1 or more ports. The twisted app connects to this server and usually connects to a few of the open ports at a time. This server is a serial logger that connects to serial devices and provides the serial line information through a raw TCP Socket an...
Hi,
I have a C application which provides a "shell" for entering commands. I'm trying to write some automated test-code for the application (Using CUnit). The "shell" input is read from stdin like so:
fgets(buf, sizeof(buf), stdin);
I can "write" commands automatically to the application by freopen()'ning stdin and hooking it to an i...
Is it possible (on iPhone/iPod Touch) for a file written like this:
if (FILE* file = fopen(filename, "wb")) {
fwrite(buf, buf_size, 1, file);
fclose(file);
}
to get corrupted, e.g. when app is forced to terminate?
From what I know fwrite should be an atomic operation, so when I write whole file with one instruction no corrup...
I have an application that runs the a command as below:
<command> <switches> >& /dev/null
I can configure <command>, but I have no control over <switches> . All the output generated by this command goes to /dev/null. I want the output to be visible on screen or redirected to a log file.
I tried to use freopen() and related functions t...
I'm using VS 2010, and I'm wondering how I can get my c++ program to read a file using standard input while debugging. I know how to do it from command prompt, but not when debugging.
Basically I want it to read in a file with cin>> instead of me typing stuff - but in debug mode.
...
Hi there, I've been trying to get back into coding for a while, so I figured I'd start with some simple SDL, now, without the file i/o, this compiles fine, but when I throw in the stdio code, it starts throwing errors. This I'm not sure about, I don't see any problem with the code itself, however, like I said, I might as well be a newbie...
So I've been digging into how the stdio portion of libc is implemented and I've come across another question. Looking at man setvbuf I see the following:
When the first I/O operation occurs on
a file, malloc(3) is called, and a
buffer is obtained.
This makes sense, your program should have a malloc in it for I/O unless you actu...
Hi. I'm trying to read the contents of a file into my program but I keep occasionally getting garbage characters at the end of the buffers. I haven't been using C a lot (rather I've been using C++) but I assume it has something to do with streams. I don't really know what to do though. I'm using MinGW.
Here is the code (this gives me ga...
I'm trying to read a return delimited file. full of phrases.
I'm trying to put each phrase into a string.
The problem is that when I try to read the file with
fscanf(file,"%50s\n",string);
the string only contains one word. when it bumps with a space it stops reading the string
...
Hi,
I don't like to use <iostream> in C++ Library. I prefer to use something that is similar to "printf" and "scanf" in <stdio.h>.
Can I use Boost's format library to replace <iostream> in all my C++ program ?
...
Hello,
Can anyone briefly explain how do these two commands work ?
isdigit and isalpha .. Ofcourse I read online sources before asking the question, but unfortunately I tried them and didnt get them to work.
What is the simplest way ?
I know it gives back a value, so im assuming I can use it like this :
if(isdigit(someinput)==1)
r...
I have been doing Java on and off for about 14 years, and almost nothing else the last 6 years or so.
I really hate the java.io package -- its legion of subclasses and adapters. I do like exceptions, rather than having to always poll "errno" and the like, but I could surely live without declared exceptions.
Is there anything that fu...
How to capture standard I/O of iPhone?
For private development purpose, not for public release.
I'm trying some kind of irregular things.
ex)
Printing network stream input to both of iPhone console, and screen.
Redirecting console output to network stream.
Redirecting NSLog output to my own program.
... (and more)
...
Is there any possibility to achieve different redirections for standard output like printf(3) for different POSIX thread? What about standard input?
I have lot of code based on standard input/output and I only can separate this code into different POSIX thread, not process. Linux operation system, C standard library.
I know I can refact...
Hi,
I use Eclipse. When I have an application like this:
write 20 times 'Hello World\n' to stdout
write 'ERROR\n' to stderr
write 5 times 'Hello World\n' to stdout
The output looks many times like this:
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
...
Hello World
Hello World
Hello World
ERROR
Is there a...
The c++ program below fails to read the file. I know using cstdio is not good practice but that what I am used to and it should work anyway.
$ ls -l l.uyvy
-rw-r--r-- 1 atilla atilla 614400 2010-04-24 18:11 l.uyvy
$ ./a.out l.uyvy
Read 0 bytes out of 614400, possibly wrong file
code:
#include<cstdio>
int main(int argc, char* argv[...
Usually I can change stdout in python by changing the value of sys.stdout. However, this only seems to affect print statements. So, is there any way I can suppress the output (to the console), of a program that is run via the os.system() command in python?
Thank you
...
Is the following program a valid C program?
#include <stdio.h>
int main()
{
fwrite("x", 1, 1, stderr);
fflush(stderr);
fgetc(stderr);
fwrite("y", 1, 1, stderr);
return 0;
}
Notice that I try to read from stderr.
When I compile it in Visual C++ 2008, and run it, I get the following output:
xy
which makes sense....