I've been using atoi() to read a field in a text file and store the binary number in an unsigned int field of a struct. From what I can tell, the results are not what I want if the number is within...
Type: Posts; User: Alogon
I've been using atoi() to read a field in a text file and store the binary number in an unsigned int field of a struct. From what I can tell, the results are not what I want if the number is within...
After looking at the assembler code, I seem to be mistaken about this.
The first example, declaring an array, produces assembler code that does not contain the text as such anywhere. Instead,...
This is a small matter, but I am curious.
In a program, main() has this line twice:
printf("key %u not found\n", key);
A naive compiler might store the format text twice, although it...
Good idea! I'll do that. Thank you.
Is there a way for a C program to determine whether its output to stdout is being redirected?
(I would like to be able to display to stderr more warning messages if it is redirected than if not).
Perhaps it should accept a character pointer (to an address in the input buffer or record) instead of an integer argument, since it isn't actually a proper integer with the wrong endianism.
I've found a need to reverse the endianness of integer data read from some files I'm working with. So I wrote the following:
typedef unsigned int uint;
typedef unsigned char byte;
uint...
>If you use the C99 version of the C standard VLA are legal, I don't recommend their use but they are legal.
My education has now been updated. I too had assumed that they were not legal. Thank...
Thanks! My program reads the files in binary mode. It makes no difference whether they are binary files or not.
From what I can grasp, if I don't call setbuf, then the system uses its own buffer...
Running Windows, I'm using gcc as provided by Strawberry Perl.
If I #define BUFSIZ 1024, I get a warning that in stdio.h it is already
defined as 512.
No problem, really. I can still...
Very interesting idea. But the article says "a query returns either "possibly in set" or "definitely not in set." Are Bloom filters most appropriate for applications that seek only exact matches? As...
This is more an algorithm question than a C language question at this stage. Can anyone refer me to article(s) that a non-mathematician can understand on the technique of using hashes to search a...
Maybe I'm missing something, but in the format field for printf() etc., I don't see a distinction between float variables and double variables. So how does the function know the size of the argument...
Over the last few hours, I've studied what a few sites have to say about error handling in C. They all begin by saying that error handling facilities are very limited, almost non-existent. There...
This peasant's algorithm is interesting. If one must repeatedly multiply numbers by a single known multiplier such as 40, it's at least tempting to use addition and shifting rather than actual...
If a file has been properly opened and then corrupt data interferes with further I/O in the same file or another file, what would constitute graceful handling? The program needs to provide as...
And I was hoping to use exit() to simplify the challenge of file I/O errors which should be rare but must always be anticipated. If we must preclude registering a function to free memory at exit,...
I've written a simple void function that merely displays a string, and registered it with atexit().
This function is called regardless of whether I end main() with exit() or return().
Are these...
Thanks, I'm following your advice in this case.
But here's another:
1. Main() uses malloc() to allocate a block of memory.
2. A function other than main() calls exit().
3. Exit()...
Shouldn't we write '\0' even if n==0, giving us an empty string corresponding to 0 bytes read?
Just out of curiosity, are there any modern systems that implement it differently than by means of a stack?
My first exposure to assembler programming was for the IBM 360, and it was nightmarish,...
Here's my solution. It took me an embarrassing amount of time, not having used C for several years.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int...
Agreed. But the program I'm working on reads a random-access file at several points, and a few of these should be in separate functions. It seems more reasonable to make the FILE * a global variable...
Prior to main(), a C source file might contain:
#pragma..
#include...
#define...
typedef...
global variables
function prototypes (headers)
functions?
and probably half-a-dozen other things...
"Static" is a key word with which you can define variables in a function. It means that the variable is private to the function but retained between calls of the function. So, unlike ordinary local...