<< < 2 3 4 5 6 7 8 9 10 11 12 > >>   Sort: Rank

Why are some ANSI ISO Standard library functions showing you
Why are some ANSI/ISO Standard library functions showing up as undefined, even though I've got an ANSI compiler? It's possible to have a compiler available which accepts ANSI syntax, but not to have ANSI-compatible header files or run-time libraries installed. (In fact, this situation is rather comm...
2015-11-30, 1169👍, 0💬

Does anyone have a tool for converting old-style C programs to ANSI C?
Does anyone have a tool for converting old-style C programs to ANSI C, or vice versa, or for automatically generating prototypes? Two programs, protoize and unprotoize, convert back and forth between prototyped and ``old style'' function definitions and declarations. (These programs do not handle fu...
2015-11-25, 1452👍, 0💬

Why wont the Frobozz Magic C Compiler ...
Why won't the Frobozz Magic C Compiler, which claims to be ANSI compliant, accept this code? I know that the code is ANSI, because gcc accepts it. Many compilers support a few non-Standard extensions, gcc more so than most. Are you sure that the code being rejected doesn't rely on such an extension?...
2015-11-25, 1293👍, 0💬

People seem to make a point of distinguishing between ...
People seem to make a point of distinguishing between implementation-defined, unspecified, and undefined behavior. What do these mean? First of all, all three of these represent areas in which the C Standard does not specify exactly what a particular construct, or a program which uses it, must do. T...
2015-11-23, 1148👍, 0💬

What does it really mean for a program to be legal or `valid or ``conforming?
What does it really mean for a program to be legal or `valid or ``conforming? Simply stated, the Standard talks about three kinds of conformance: conforming programs, strictly conforming programs, and conforming implementations. A conforming program is one that is accepted by a conforming implementa...
2015-11-23, 1207👍, 0💬

I am appalled that the ANSI Standard leaves so many issues undefined ...
I'm appalled that the ANSI Standard leaves so many issues undefined. Isn't a Standard's whole job to standardize these things? It has always been a characteristic of C that certain constructs behaved in whatever way a particular compiler or a particular piece of hardware chose to implement them. Thi...
2015-11-18, 1147👍, 0💬

People keep saying that the behavior of ...
People keep saying that the behavior of i = i++ is undefined, but I just tried it on an ANSI-conforming compiler, and got the results I expected. A compiler may do anything it likes when faced with undefined behavior (and, within limits, with implementation-defined and unspecified behavior), includi...
2015-11-18, 1125👍, 0💬

What is wrong with this code?
What's wrong with this code? char c; while((c = getchar()) != EOF) ... For one thing, the variable to hold getchar's return value must be an int. EOF is an ``out of band'' return value from getchar: it is distinct from all possible char values which getchar can return. (On modern systems, it does no...
2015-11-16, 1198👍, 0💬

I have a simple little program that reads characters until EOF ...
I have a simple little program that reads characters until EOF, but how do I actually enter that ``EOF'' value from the keyboard? I see that EOF is defined by to be -1; am I supposed to enter -1? If you think about it, what you enter can't be -1, because ``-1'' is two characters, and getchar is read...
2015-11-16, 1136👍, 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, 1159👍, 0💬

Why do all the lines end up containing copies of the last line?
I'm using fgets to read lines from a file into an array of pointers. Why do all the lines end up containing copies of the last line? You have only allocated memory for one line, linebuf. Each time you call fgets, the previous line is overwritten. fgets doesn't do any memory allocation: unless it rea...
2015-11-13, 1109👍, 0💬

My programs prompts and intermediate output dont always show up on the screen ...
My program's prompts and intermediate output don't always show up on the screen, especially when I pipe the output through another program. It's best to use an explicit fflush(stdout) whenever output should definitely be visible (and especially if the text does not end with \n). Several mechanisms a...
2015-11-11, 1137👍, 0💬

How can I read one character at a time, without waiting for the RETURN key
How can I read one character at a time, without waiting for the RETURN key Alas, there is no standard or portable way to do these things in C. Concepts such as screens and keyboards are not even mentioned in the Standard, which deals only with simple I/O ``streams'' of characters. Input to a compute...
2015-11-11, 1365👍, 0💬

How can I print a character in a printf format string?
How can I print a '%' character in a printf format string? I tried \%, but it didn't work. Simply double the percent sign: %% . The reason it's tricky to print % signs with printf is that % is essentially printf's escape character. Whenever printf sees a %, it expects it to be followed by a characte...
2015-11-09, 1291👍, 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, 1162👍, 0💬

I thought that ANSI function prototypes were supposed to guard against argument type mismatches.
I thought that ANSI function prototypes were supposed to guard against argument type mismatches. When a function accepts a variable number of arguments, its prototype does not (and cannot) provide any information about the number and types of those variable arguments. Therefore, the usual protection...
2015-11-06, 1198👍, 0💬

How can printf use f for type double, if scanf requires lf?
Someone told me it was wrong to use %lf with printf. How can printf use %f for type double, if scanf requires %lf? It's true that printf's %f specifier works with both float and double arguments Due to the ``default argument promotions'' (which apply in variable-length argument lists values of type ...
2015-11-06, 1219👍, 0💬

What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type?
What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type? Use a cast to convert the value to a known, conservatively-sized type, then use the printf format matching that type. For example, to print the size of a type, you might use printf("%lu...
2015-11-04, 1151👍, 0💬

How can I print numbers with commas separating the thousands? What about currency formatted numbers?
How can I print numbers with commas separating the thousands? What about currency formatted numbers? The functions in &lt;locale.h> begin to provide some support for these operations, but there is no standard C function for doing either task. (In Standard C, the only thing printf does in respons...
2015-11-02, 1715👍, 0💬

Why doesnt the call scanf work?
Why doesn't the call scanf("%d", i) work? The arguments you pass to scanf must always be pointers: for each value converted, scanf ``returns'' it by filling in one of the locations you've passed pointers to. To fix the fragment above, change it to scanf("%d", &i) .
2015-11-02, 1183👍, 0💬

Why does the call char scanf work?
Why does the call char s[30]; scanf("%s", s); work? I thought you always needed an & on each variable passed to scanf. You always need a pointer; you don't necessarily need an explicit &amp;. When you pass an array to scanf, you do not need the &, because arrays are always passed to func...
2015-10-30, 1088👍, 0💬

Why doesnt this code work?
Why doesn't this code: double d; scanf("%f", &amp;d); work? Unlike printf, scanf uses %lf for values of type double, and %f for float.%f tells scanf to expect a pointer-to-float, not the pointer-to-double you gave it. Either use %lf, or declare the receiving variable as a float.
2015-10-30, 1089👍, 0💬

Why doesnt that code work?
Why doesn't the code short int s; scanf("%d", &s); work? When converting %d, scanf expects a pointer to an int. To convert to a short int, use %hd .
2015-10-28, 1033👍, 0💬

How can I specify a variable width in a scanf format string?
How can I specify a variable width in a scanf format string? You can't; an asterisk in a scanf format string means to suppress assignment. You may be able to use ANSI stringizing and string concatenation to construct a constant format specifier based on a preprocessor macro containing the desired wi...
2015-10-26, 1158👍, 0💬

<< < 2 3 4 5 6 7 8 9 10 11 12 > >>   Sort: Rank