<< < 10 11 12 13 14 15 16 17 > >>   Sort: Date

How can I find out if there are characters available for reading?
How can I find out if there are characters available for reading (and if so, how many)? Alternatively, how can I do a read that will not block if there are no characters available? These, too, are entirely operating-system-specific. Some versions of curses have a nodelay function. Depending on your ...
2015-04-29, 1085👍, 0💬

I am starting to think about multinational character sets ....
I'm starting to think about multinational character sets, and I'm worried about the implications of making sizeof(char) be 2 so that 16-bit character sets can be represented. If type char were made 16 bits, sizeof(char) would still be 1, and CHAR_BIT in &lt;limits.h> would be 16, and it would si...
2016-03-02, 1083👍, 0💬

I have an old macro that doesn't seem to work any more....
I have an old macro #define CTRL(c) ('c' &amp; 037) that doesn't seem to work any more. The intended use of this macro is in code like tchars.t_eofc = CTRL(D); which is expected to expand to tchars.t_eofc = ('D' &amp; 037); based on the assumption that the actual value of the parameter c wil...
2016-01-25, 1081👍, 0💬

I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it? See if you can run lint first (perhaps with the -a, -c, -h, -p or other options ). Many C compilers are really only half-compilers, taking the attitude that it's not their problem if you didn't say what you...
2015-05-06, 1080👍, 0💬

How can I insert or delete a line (or record) in the middle of a file?
How can I insert or delete a line (or record) in the middle of a file? In general, there is no way to do this. The usual solution is simply to rewrite the file. When you find yourself needing to insert data into an existing file, here are a few alternatives you can try: * Rearrange the data file so ...
2015-04-13, 1078👍, 0💬

How can I write a function that takes a variable number of arguments?
How can I write a function that takes a variable number of arguments? Use the facilities of the &lt;stdarg.h> header. Here is a function which concatenates an arbitrary number of strings into malloc'ed memory: #include &lt;stdlib.h> /* for malloc, NULL, size_t */ #include &lt;stdarg.h> /...
2015-06-15, 1075👍, 0💬

I cant get strcat to work. I tried ...
I can't get strcat to work. I tried char *s1 = "Hello, ";br> char *s2 = "world!";br> char *s3 = strcat(s1, s2);br> but I got strange results. the main problem here is that space for the concatenated result is not properly allocated. C does not provide an automatically-managed string type. C compiler...
2016-03-09, 1073👍, 0💬

My floating-point calculations are acting strangely and giving me different answers on different machines.
My floating-point calculations are acting strangely and giving me different answers on different machines. If the problem isn't that simple, recall that digital computers usually use floating-point formats which provide a close but by no means exact simulation of real number arithmetic. Among other ...
2015-06-29, 1072👍, 0💬

How can I find out how much free space is available on disk?
How can I find out how much free space is available on disk? There is no portable way. Under some versions of Unix you can call statfs. Under MS-DOS, use interrupt 0x21 subfunction 0x36, or perhaps a routine such as diskfree. Another possibility is to use popen to invoke and read the output of a ``d...
2015-04-03, 1072👍, 0💬

How can I open files with names like ...
How can I open files with names like ``file1'', ``file2'', ``file3'', etc., where the numeric part is controlled by a variable? Basically I want ``file%d'', like printf.. You want printf's close cousin sprintf, which ``prints'' to a string: char filename[FILENAME_MAX]; sprintf(filename, "file%d", i)...
2015-10-07, 1071👍, 0💬

What is alloca and why is its use discouraged?
What is alloca and why is its use discouraged? alloca allocates memory which is automatically freed when the function which called alloca returns. That is, memory allocated with alloca is local to a particular function's ``stack frame'' or context. alloca cannot be written portably, and is difficult...
2016-03-14, 1067👍, 0💬

How should functions be apportioned among source files?
How should functions be apportioned among source files? Usually, related functions are put together in one file. Sometimes (as when developing libraries) it is appropriate to have exactly one source file (and, consequently, one object module) per independent function. Other times, and especially for...
2015-05-18, 1065👍, 0💬

What are pragmas and what are they good for?
What are pragmas and what are they good for? The #pragma directive provides a single, well-defined ``escape hatch'' which can be used for all sorts of (nonportable) implementation-specific controls and extensions: source listing control, structure packing, warning suppression (like lint's old /* NOT...
2015-12-11, 1063👍, 0💬

How can I sort more data than will fit in memory?
How can I sort more data than will fit in memory? You want an ``external sort,'' which you can read about in Knuth, Volume 3. The basic idea is to sort the data in chunks (as much as will fit in memory at one time), write each sorted chunk to a temporary file, and then merge the files. Your operatin...
2015-08-07, 1063👍, 0💬

A third-party header file I just started using is defining its own TRUE and FALSE values incompatibly ...
A third-party header file I just started using is defining its own TRUE and FALSE values incompatibly with the code I've already developed. What can I do? This is indeed an annoying situation. It's a classic namespace problem;Ideally, third-party vendors would be conscientious when defining symbols ...
2016-02-26, 1061👍, 0💬

Why is the macro giving me the warning
Why is the macro #define TRACE(n) printf("TRACE: %d\n", n) giving me the warning ``macro replacement within a string literal''? It seems to be expanding TRACE(count); as printf("TRACE: %d\count", count); Some pre-ANSI compilers/preprocessors interpreted macro definitions like #define TRACE(var, fmt)...
2016-01-25, 1059👍, 0💬

I am using scanf c to read a Y/N response
I'm using scanf %c to read a Y/N response, but later input gets skipped. You wanted scanf %c to read a single character, and it tried to, but when you tried to type that single character at it, before the rest of the input system would accept it, you had to hit the RETURN key, too. scanf read only t...
2015-10-21, 1059👍, 0💬

How can I write a function analogous to scanf
How can I write a function analogous to scanf, i.e. that accepts similar arguments, and calls scanf to do most of the work? C99 (but not any earlier C Standard) supports vscanf, vfscanf, and vsscanf.
2015-06-12, 1059👍, 0💬

I am trying to port this old program. Why do I get undefined external errors for some library functions?
I am trying to port this old program. Why do I get undefined external errors for some library functions? Some old or semistandard functions have been renamed or replaced over the years; if you need:/you should instead: index use strchr. rindex use strrchr. bcopy use memmove, after interchanging the ...
2015-07-16, 1058👍, 0💬

What is the difference between ...
What's the difference between const MAXSIZE = 100; and #define MAXSIZE 100 A preprocessor #define gives you a true compile-time constant. In C, const gives you a run-time object which you're not supposed to try to modify; ``const'' really means ``readonly''.
2016-02-18, 1055👍, 0💬

What's the difference between...?
What's the difference between #include &lt;> and #include "" ? The syntax is typically used with Standard or system-supplied headers, while "" is typically used for a program's own header files.
2016-02-16, 1054👍, 0💬

When I read numbers from the keyboard with scanf ...
When I read numbers from the keyboard with scanf and a "%d\n" format, like this: int n; scanf("%d\n", &amp;n); printf("you typed %d\n", n); it seems to hang until I type one extra line of input. Perhaps surprisingly, \n in a scanf format string does not mean to expect a newline, but rather to re...
2015-10-23, 1050👍, 0💬

Why does everyone say not to use gets?
Why does everyone say not to use gets? Unlike fgets(), gets() cannot be told the size of the buffer it's to read into, so it cannot be prevented from overflowing that buffer if an input line is longer than expected--and Murphy's Law says that, sooner or later, a larger-than-expected input line will ...
2015-10-16, 1050👍, 0💬

How can I add N days to a date? How can I find the difference between two dates?
How can I add N days to a date? How can I find the difference between two dates? The ANSI/ISO Standard C mktime and difftime functions provide some (limited) support for both problems. mktime accepts non-normalized dates, so it is straightforward to take a filled-in struct tm, add or subtract from t...
2015-08-05, 1048👍, 0💬

<< < 10 11 12 13 14 15 16 17 > >>   Sort: Date