stdio

stdlib and colored output in C

I am making a simple application which requires colored output. How can I make my output colored like emacs and bash do? I don't care about Windows, as my application is only for UNIX systems. Thanks. ...

Filehandle for Output from System Command in Perl

Is there a filehandle/handle for the output of a system command I execute in Perl? ...

python 2.7 / exec / what is wrong?

Hello, I have this code which runs fine in Python 2.5 but not in 2.7: import sys import traceback try: from io import StringIO except: from StringIO import StringIO def CaptureExec(stmt): oldio = (sys.stdin, sys.stdout, sys.stderr) sio = StringIO() sys.stdout = sys.stderr = sio try: exec(stmt, globals()...

Store user-input in a variable

I was wondering how I could prompt the end-user of my program to type in a value they want to be converted from Fahrenheit into Celsius in C. Basically, since I'm a total n00b and I'm writing amazing "programs" such as this one: //Simple program to convert Fahrenheit to Celsius int main (int argc, char *argv[]) { doub...

String Stream in C

print2fp(const void *buffer, size_t size, FILE *stream) { if(fwrite(buffer, 1, size, stream) != size) return -1; return 0; } How to write the data into string stream instead of File stream? ...

Python and C++ integration. Python prints string as multiple lines.

I'm trying to write a program in python to run a program in C++. It wasn't working right, so I made the most basic version of each I could. The C++ program merely takes in a string from stdin, and then prints it out. The Python code is written as follows: import popen2, string, StringIO fin, fout = popen2.popen2("PyTest") msg = ur"Hel...

fread Only first 5 bytes of .PNG file

I've made a simple resource packer for packing the resources for my game into one file. Everything was going fine until I began writing the unpacker. I noticed the .txt file - 26 bytes - that I had packed, came out of the resource file fine, without anyway issues, all data preserved. However when reading the .PNG file I had packed in the...

C - printf and scanf - How do I terminate input?

I am working on a simple application written in C. I am working in a Unix environment. My application is doing some simple I/O. I use printf to prompt the user for some input and then use scanf to get that input. The problem is, I don't know how to tell my application that I am ready to proceed after entering in a value. Typing 'enter'...

Making fgets issue longer read() calls on linux

I'm reading quite large lines(up to 128K) of text using fgets. I'm seeing excessive context switching on the server, using strace I see the following: read(3, "9005 10218 00840023102015 201008"..., 4096) = 4096 i.e. fgets reads chunks of 4096 bytes at a time. Is there any way to control how big chunks fgets uses to when calling read()...

Are System.out, stdout and cout the exact same thing ?

Are System.out, stdout and cout the EXACT same thing in Java, C and C++ respectively? Why have three different names for the same thing (especially when C, C++ and Java have much in common)? Also, I know what they are used for but what are they exactly, under the hood, I mean? ...

Tips on how to read last 'word' in a character array in C

Just looking to be pointed in the right direction: Have standard input to a C program, I've taken each line in at a time and storing in a char[]. Now that I have the char[], how do I take the last word (just assuming separated by a space) and then convert to lowercase? I've tried this but it just hangs the program: while (sscanf(line...

Find all a substring's occurrences and locations

Hello guys, I'm writing a program to parse some data saved as text files. What I am trying to do is find the location of every needle in a haystack. I already can read the file in and determine the number of occurrences, but I am looking to find the index also. Thanks, -Tom ...