<< < 169 170 171 172 173 174   Sort: Date

How can I tell if standard input or output is redirected
How can I tell if standard input or output is redirected (i.e. whether ``&lt;'' or ``&gt;'' was used on the invocation command line)? You can't tell directly, but you can usually look at a few other things to make whatever decision you need to. If you want your program to take input from std...
2015-10-01, 1067👍, 0💬

How can I write code to conform to these old, binary data file formats?
How can I write code to conform to these old, binary data file formats? It's hard, because of word size and byte order differences, floating-point formats, and structure padding. To get the control you need over these particulars, you may have to read and write things a byte at a time, shuffling and...
2015-09-18, 1065👍, 0💬

How can I recover the file name given an open stream?
How can I recover the file name given an open stream? This problem is, in general, insoluble. Under Unix, for instance, a scan of the entire disk (perhaps involving special permissions) would theoretically be required, and would fail if the descriptor were connected to a pipe or referred to a delete...
2015-10-05, 1064👍, 0💬

I know that the library function localtime will convert ...
I know that the library function localtime will convert a time_t into a broken-down struct tm, and that ctime will convert a time_t to a printable string. How can I perform the inverse operations of converting a struct tm or a string into a time_t? ANSI C specifies a library function, mktime, which ...
2015-08-05, 1059👍, 0💬

How can I read data from data files with particular formats?
How can I read data from data files with particular formats? How can I read ten floats without having to use a jawbreaker scanf format like "%f %f %f %f %f %f %f %f %f %f"? How can I read an arbitrary number of fields from a line into an array? In general, there are three main ways of parsing data l...
2015-10-26, 1054👍, 0💬

What is the deal on sprintfs return value?
What's the deal on sprintf's return value? Is it an int or a char *? The Standard says that it returns an int (the number of characters written, just like printf and fprintf). Once upon a time, in some C libraries, sprintf returned the char * value of its first argument, pointing to the completed re...
2015-10-16, 1051👍, 0💬

I cant even get a simple fopen call to work
I can't even get a simple fopen call to work! What's wrong with this call? FILE *fp = fopen(filename, 'r'); fopen's mode argument must be a string, like "r", not a character like 'r'.
2015-10-09, 1051👍, 0💬

What is the difference between text and binary I/O?
What is the difference between text and binary I/O? In text mode, a file is assumed to consist of lines of printable characters (perhaps including tabs). The routines in the stdio library (getc, putc, and all the rest) translate between the underlying system's end-of-line representation and the sing...
2015-09-21, 1050👍, 0💬

I am getting strange syntax errors on the very first declaration in a file, but it looks fine.
I am getting strange syntax errors on the very first declaration in a file, but it looks fine. Perhaps there's a missing semicolon at the end of the last declaration in the last header file you're #including.
2016-02-12, 1033👍, 0💬

I wrote this routine which is supposed to open a fi
I wrote this routine which is supposed to open a file: myfopen(char *filename, FILE *fp) { fp = fopen(filename, "r"); } But when I call it like this: FILE *infp; myfopen("filename.dat", infp); the infp variable in the caller doesn't get set properly. Functions in C always receive copies of their arg...
2015-10-09, 1015👍, 0💬

I want to read and write numbers between files and memory ...
I want to read and write numbers between files and memory in a byte-at-a-time way, not as formatted characters the way fprintf and fscanf do. How can I do this? What you're trying to do is usually called ``binary'' I/O. First, make sure that you are calling fopen with the "b" modifier ("rb", "wb", e...
2015-09-24, 959👍, 0💬

<< < 169 170 171 172 173 174   Sort: Date