<< < 167 168 169 170 171 172 173 174 > >>   Sort: Date

How can I shut off the warning ...
How can I shut off the ``warning: possible pointer alignment problem'' message which lint gives me for each call to malloc? A modern lint shouldn't be complaining about this. Once upon a time, lint did not and could not know that malloc ``returns a pointer to space suitably aligned for storage of an...
2015-05-05, 1133👍, 0💬

I think somethings wrong with my compiler ...
I think something's wrong with my compiler: I just noticed that sizeof('a') is 2, not 1 (i.e. not sizeof(char)). Perhaps surprisingly, character constants in C are of type int, so sizeof('a') is sizeof(int) (though this is another area where C++ differs).
2016-03-04, 1132👍, 0💬

Is if(p), where p is a pointer, a valid and portable test?
Is if(p), where p is a pointer, a valid and portable test? It is always valid. When C requires the Boolean value of an expression, a false value is inferred when the expression compares equal to zero, and a true value otherwise. That is, whenever one writes if(expr) where ``expr'' is any expression ...
2016-02-29, 1130👍, 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, 1130👍, 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-10-05, 1128👍, 0💬

Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme
Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme rogramming style, like writing style, is somewhat of an art and cannot be codified by inflexible rules, although discussions about style often seem to center exclusively around such rules. In the case of th...
2015-05-08, 1128👍, 0💬

If I can say... why can't I say...
If I can say char a[] = "Hello, world!"; why can't I say char a[14]; Strings are arrays, and you can't assign arrays directly. Use strcpy instead: strcpy(a, "Hello, world!");
2016-03-11, 1125👍, 0💬

I am trying to define a few simple little function-like macros ...
I'm trying to define a few simple little function-like macros such as #define square(x) x * x but they're not always working. There are three important rules to remember when defining function-like macros: 1. The macro expansion must always be parenthesized to protect any lower-precedence operators ...
2016-02-26, 1125👍, 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, 1123👍, 0💬

My compiler isnt letting me declare a function
My compiler isnt letting me declare a function A; My compiler isn't letting me declare a function int f(...) { } i.e. accepting a variable number of arguments, but with no fixed arguments at all. A: Standard C requires at least one fixed argument, in part so that you can hand it to va_start. (In any...
2015-06-08, 1120👍, 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, 1117👍, 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, 1115👍, 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, 1115👍, 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, 1111👍, 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, 1111👍, 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, 1109👍, 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, 1108👍, 0💬

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, 1108👍, 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, 1102👍, 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, 1101👍, 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, 1101👍, 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, 1098👍, 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, 1097👍, 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, 1096👍, 0💬

<< < 167 168 169 170 171 172 173 174 > >>   Sort: Date