<< < 162 163 164 165 166 167 168 169 170 171 172 > >>   Sort: Date

Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0?
Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0? It's your choice. Preprocessor macros like TRUE and FALSE (and, of course, NULL) are used for code readability, not because the underlying values might ever change. It's a matter of style, not correctness, wheth...
2016-02-29, 1264👍, 0💬

How can I use a macro argument inside a string literal in the macro expansion?
How can I use a macro argument inside a string literal in the macro expansion? Some pre-ANSI compilers/preprocessors interpreted macro definitions like #define TRACE(var, fmt) printf("TRACE: var = fmt\n", var) such that invocations like TRACE(i, %d); were expanded as printf("TRACE: i = %d\n", i); In...
2016-01-22, 1264👍, 0💬

When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999? Most computers use base 2 for floating-point numbers as well as for integers, and just as for base 10, not all fractions are representable exactly in base 2. It's well-known that in base 10, a fraction like 1/3 = 0.333...
2015-07-03, 1264👍, 0💬

How can I write a function which takes a variable number of arguments
How can I write a function which takes a variable number of arguments and passes them to some other function (which takes a variable number of arguments)? In general, you cannot. Ideally, you should provide a version of that other function which accepts a va_list pointer. Suppose you want to write a...
2015-06-05, 1263👍, 0💬

How can I call system when parameters (filenames, etc.) of the executed command arent known until run time?
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time? Just use sprintf (or perhaps strcpy and strcat) to build the command string in a buffer, then call system with that buffer. (Make sure the buffer is allocated with enough space; Here is a cont...
2015-03-18, 1263👍, 0💬

How do I get an accurate error status return from system on MS-DOS?
How do I get an accurate error status return from system on MS-DOS? You can't; COMMAND.COM doesn't tend to provide one. If you don't need COMMAND.COM's services (i.e. if you're just trying to invoke a simple program, without I/O redirection and such) try one of the spawn routines, instead.
2015-03-16, 1263👍, 0💬

I mm compiling a program, and I seem to be missing one of the header files it requires
I mm compiling a program, and I seem to be missing one of the header files it requires There are several situations, depending on what sort of header file it is that's ``missing''. If the missing header file is truly a standard one (that is, one defined by the ANSI C Standard, such as &lt;stdio....
2016-02-05, 1262👍, 0💬

How can I write a function that takes a format string and a variable number of arguments
How can I write a function that takes a format string and a variable number of arguments, like printf, and passes them to printf to do most of the work? Use vprintf, vfprintf, or vsprintf. These routines are like their counterparts printf, fprintf, and sprintf, except that instead of a variable-leng...
2015-06-12, 1262👍, 0💬

How can I suppress the dreaded MS-DOS Abort, Retry, Ignore? message?
How can I suppress the dreaded MS-DOS Abort, Retry, Ignore? message? Among other things, you need to intercept the DOS Critical Error Interrupt, interrupt 24H. See the comp.os.msdos.programmer
2015-04-06, 1262👍, 0💬

What are near and far pointers?
What are near and far pointers? These days, they're pretty much obsolete; they're definitely system-specific. They had to do with 16-bit programming under MS-DOS and perhaps some early versions of Windows. If you really need to know, see a DOS- or Windows-specific programming reference. If you're us...
2015-03-02, 1261👍, 0💬

Why does the declaration extern int .....
Why does the declaration extern int f(struct x *p); give me an obscure warning message about ``struct x declared inside parameter list''? In a quirk of C's normal block scoping rules, a structure declared (or even mentioned) for the first time within a prototype cannot be compatible with other struc...
2016-01-11, 1260👍, 0💬

What does pragma once mean? I found it in some header files.
What does pragma once mean? I found it in some header files. It is an extension implemented by some preprocessors to help make header files idempotent; that is, to make sure that their contents are processed exactly once even if they are #included multiple times.Some people claim that #pragma once c...
2015-12-11, 1260👍, 0💬

What does it mean when the linker says that _end is undefined?
What does it mean when the linker says that _end is undefined? That message is a quirk of the old Unix linkers. You get an error about _end being undefined only when other symbols are undefined, too--fix the others, and the error about _end will disappear.
2015-07-06, 1260👍, 0💬

How can I increase the allowable number of simultaneously open files?
I'm getting an error, ``Too many open files''. How can I increase the allowable number of simultaneously open files? A: There are typically at least two resource limitations on the number of simultaneously open files: the number of low-level ``file descriptors'' or ``file handles'' available in the ...
2015-04-03, 1260👍, 0💬

How can I invoke another program (a standalone executable, or an operating system command) from within a C program?
How can I invoke another program (a standalone executable, or an operating system command) from within a C program? Use the library function system, which does exactly that. Some systems also provide a family of spawn routines which accomplish approximately the same thing. system is more ``portable'...
2015-03-18, 1259👍, 0💬

How do I create a directory? How do I remove a directory (and its contents)?
How do I create a directory? How do I remove a directory (and its contents)? If your operating system supports these services, they are likely to be provided in C via functions named mkdir and rmdir. Removing a directory's contents as well will require listing them and calling remove . If you don't ...
2015-04-01, 1258👍, 0💬

Why doesnt long int work?
Why doesn't long int n = 123456; printf("%d\n", n); work? Whenever you print long ints you must use the l (lower case letter ``ell'') modifier in the printf format (e.g. %ld). printf can't know the types of the arguments which you've passed to it, so you must let it know by using the correct format ...
2015-11-09, 1257👍, 0💬

Why does everyone say not to use scanf? What should I use instead?
Why does everyone say not to use scanf? What should I use instead? scanf has a number of problems, its %s format has the same problem that gets() has --it's hard to guarantee that the receiving buffer won't overflow. More generally, scanf is designed for relatively structured, formatted input (its n...
2015-10-21, 1257👍, 0💬

How do I read the arrow keys? What about function keys?
How do I read the arrow keys? What about function keys? Terminfo, some versions of termcap, and some versions of curses have support for these non-ASCII keys. Typically, a special key sends a multicharacter sequence (usually beginning with ESC, '\033'); parsing these can be tricky. (curses will do t...
2015-04-24, 1257👍, 0💬

Is exit(status) truly equivalent to returning the same status from main?
Is exit(status) truly equivalent to returning the same status from main? Yes and no. The Standard says that a return from the initial call to main is equivalent to calling exit. However, a return from main cannot be expected to work if data local to main might be needed during cleanup; A few very ol...
2015-03-09, 1257👍, 0💬

I am trying to sort an array of strings with qsort, using strcmp as the comparison function, but it is not working.
I am trying to sort an array of strings with qsort, using strcmp as the comparison function, but it is not working. By ``array of strings'' you probably mean ``array of pointers to char.'' The arguments to qsort's comparison function are pointers to the objects being sorted, in this case, pointers t...
2015-08-12, 1256👍, 0💬

I am trying to do some simple trig...
I'm trying to do some simple trig, and I am #including &lt;math.h>, but the linker keeps complaining that functions like sin and cos are undefined. Make sure you're actually linking with the math library. For instance, due to a longstanding bug in Unix and Linux systems, you usually need to use ...
2015-07-01, 1256👍, 0💬

But I cant use all these nonstandard, system-dependent functions, because my program has to be ANSI compatible!
But I cant use all these nonstandard, system-dependent functions, because my program has to be ANSI compatible! You're out of luck. Either you misunderstood your requirement, or it's an impossible one to meet. ANSI/ISO Standard C simply does not define ways of doing these things; it is a language st...
2015-02-27, 1256👍, 0💬

How can I tell how much destination buffer space ...
How can I tell how much destination buffer space I'll need for an arbitrary sprintf call? How can I avoid overflowing the destination buffer with sprintf? When the format string being used with sprintf is known and relatively simple, you can sometimes predict a buffer size in an ad-hoc way. If the f...
2015-10-19, 1255👍, 0💬

<< < 162 163 164 165 166 167 168 169 170 171 172 > >>   Sort: Date