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

Each time I run my program, I get the same sequence of numbers back from rand
Each time I run my program, I get the same sequence of numbers back from rand It's a characteristic of most pseudo-random number generators (and a defined property of the C library rand) that they always start with the same number and go through the same sequence. (Among other things, a bit of predi...
2015-07-29, 1222👍, 0💬

I am including the right header file for the library function I am using, but the linker keeps saying its undefined.
I am including the right header file for the library function I am using, but the linker keeps saying its undefined. In the general case of calling code in an external library, using #include to pull in the right header file(s) is only half of the story; you also have to tell the linker to search th...
2016-02-10, 1221👍, 0💬

I a'm getting strange syntax errors inside lines I have ifdeffed out.
I a'm getting strange syntax errors inside lines I have ifdeffed out. Under ANSI C, the text inside a ``turned off'' #if, #ifdef, or #ifndef must still consist of ``valid preprocessing tokens.'' This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't ...
2016-01-29, 1221👍, 0💬

Are the outer parentheses in return statements really optional?
Are the outer parentheses in return statements really optional? Yes. Long ago, in the early days of C, they were required, and just enough people learned C then, and wrote code which is still in circulation, that the notion that they might still be required is widespread. (As it happens, parentheses...
2015-02-02, 1221👍, 0💬

Is there anything like an ifdef for typedefs?
Is there anything like an ifdef for typedefs? Unfortunately, no. (There can't be, because types and typedefs haven't been parsed at preprocessing time.) You may have to keep sets of preprocessor macros (e.g. MY_TYPE_DEFINED) recording whether certain typedefs have been declared.
2016-02-01, 1218👍, 0💬

Why doesnt strcat work? ....
Why doesn't strcat(string, '!'); work? There is a very real difference between characters and strings, and strcat concatenates strings. A character constant like '!' represents a single character. A string literal between double quotes usually represents multiple characters. A string literal like "!...
2016-03-14, 1217👍, 0💬

Can I declare main as void, to shut off these annoying ....
Can I declare main as void, to shut off these annoying ``main returns no value'' messages? No. main must be declared as returning an int, and as taking either zero or two arguments, of the appropriate types. If you're calling exit() but still getting warnings, you may have to insert a redundant retu...
2015-12-20, 1217👍, 0💬

Having dynamically allocated an array , can I change its size?
Having dynamically allocated an array , can I change its size? Yes. This is exactly what realloc is for. Given a region of malloced memory its size can be changed using code like: dynarray = realloc(dynarray, 20 * sizeof(int)); Note that realloc may not always be able to enlarge memory regions in-pl...
2016-03-21, 1216👍, 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, 1215👍, 0💬

How can I generate floating-point random numbers?
How can I generate floating-point random numbers? drand48 is a Unix System V routine which returns floating point random numbers (presumably with 48 bits of precision) in the half-open interval [0, 1). (Its companion seed routine is srand48; neither is in the C Standard.) It's easy to write a low-pr...
2015-07-22, 1215👍, 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, 1215👍, 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, 1215👍, 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, 1215👍, 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, 1215👍, 0💬

Why cant I pass a char to a function which expects a const char ?
Why cant I pass a char to a function which expects a const char ? You can use a pointer-to-T (for any type T) where a pointer-to-const-T is expected. However, the rule (an explicit exception) which permits slight mismatches in qualified pointer types is not applied recursively, but only at the top l...
2016-01-04, 1213👍, 0💬

Why does the simple line-copying loop while ...
Why does the simple line-copying loop while(!feof(infp)) { fgets(buf, MAXLINE, infp); fputs(buf, outfp); } copy the last line twice? p> In C, end-of-file is only indicated after an input routine has tried to read, and failed. (In other words, C's I/O is not like Pascal's.) Usually, you should just c...
2015-11-13, 1213👍, 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, 1213👍, 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, 1213👍, 0💬

How can I invoke another program or command and trap its output?
How can I invoke another program or command and trap its output? Unix and some other systems provide a popen function, which sets up a stdio stream on a pipe connected to the process running a command, so that the calling program can read the output (or alternatively supply the input). Using popen, ...
2015-03-16, 1213👍, 0💬

I am trying to use the ANSI stringizing preprocessing operator ....
I'm trying to use the ANSI ``stringizing'' preprocessing operator `#' to insert the value of a symbolic constant into a message, but it keeps stringizing the macro's name rather than its value. It turns out that the definition of # says that it's supposed to stringize a macro argument immediately, w...
2016-01-22, 1212👍, 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, 1212👍, 0💬

If NULL and 0 are equivalent as null pointer constants, which should I use?
If NULL and 0 are equivalent as null pointer constants, which should I use? Many programmers believe that NULL should be used in all pointer contexts, as a reminder that the value is to be thought of as a pointer. Others feel that the confusion surrounding NULL and 0 is only compounded by hiding 0 b...
2015-05-11, 1212👍, 0💬

How can I read a directory in a C program?
How can I read a directory in a C program? See if you can use the opendir and readdir functions, which are part of the POSIX standard and are available on most Unix variants. Implementations also exist for MS-DOS, VMS, and other systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which do esse...
2015-04-01, 1212👍, 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, 1211👍, 0💬

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