Hello,
I programmed a set of functions for bit output. Trying to make my code run even faster, I came across two lines of code that looked like this:
*put_buffer |= bits >> (count -...
Type: Posts; User: kkk
Hello,
I programmed a set of functions for bit output. Trying to make my code run even faster, I came across two lines of code that looked like this:
*put_buffer |= bits >> (count -...
I tried running the code outside my IDE and it worked. So the problem is in the IDE!
Hello,
I tried the following code to experiment with EOF:
int c;
while(1)
Thanks for your valuable post, I now get it! Perfect! Thanks again!
Just read it. What I don't get is that EOF works as described on stack overflow in the while(1) loop in post #8 and doesn't work like that in the function in my original post - it doesn't flush the...
How is "entering" EOF supposed to work in programs then? I figure it just sends the input text/string for processing to my program, very much like a newline (enter) does. Am I getting it wrong?
...
If I enter some text and press CTRL+D twice, the breakpoint gets triggered twice! The first time reading the text/string and returning its length, the second time reading an empty string and...
*nix (Mac OS X 10.7 with XCode 4)
Hello,
I tried to experiment with the code in K & R chapter 1.9 (a program that reads a set of text lines and prints the longest) and I was getting weird results when entering EOF (pressing CTRL+D...
Why would one want to do that in the first place? :-)
How would you improve the code then, please?
I tried to write two pieces of code that would be clean, readable and as much "textbook-like"...
Hello,
I tried to code one of the exercises in K&R, namely the one in which you are supposed to read the input and output it one word per line.
I've come up with two functions, the only...
Hello,
I've written two functions doing binary search. This wasn't a homework assignment, I just did that for fun. Which of the two functions do you like more?
int binary_search1(int *arr,...
Yep, that's what I overlooked, thanks. And why did I overlook it? Because I didn't get a message in the XCode debug window that the program terminated... Strange. That's why I thought it was waiting...
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 5
char numbers[MAXSIZE + 1];
int myatoi(const char *str)
{
int val = 0;
I did consult the man pages and I did try to look it up on the internet. There was nothing about what fgets does with the characters it doesn't "put" in the string.
That's why I asked. Sorry if it...
Hello,
I'm aware that scanf is a bit "nasty" because it often leaves "undigested" characters in the input stream. What about fgets used to input a string from stdin? I tried entering more...
Hello,
the following excerpt is taken from "The C Programming Language" by K & R:
main()
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
Hello,
I've written the following code to convert time in seconds to time in hours, minutes and seconds. The time in seconds is stored in the variable total, there's no user input yet. Is my code...
Yes, incrementing it by one each time I increment the buffer pointer.
Hello,
I'm programming a set of functions for bit output. This will be buffered, suppose I have two pointers:
unsigned char *buffer, *buffer_start;
The pointer buffer points to the current...
Hello,
I have a silly question:
Why do programmers use the ternary operator as shown in the abs2 function with the extra pair of brackets enclosing the conditional statement? To improve...
Hello,
are all the ways to access a member of a two-dimensional array listed below correct? I've tested the code and it seems to work properly.
void do_something(int (*ap)[COLUMNS], int rows,...
Hi,
if I get it right, ap in the following example is a pointer to an array of 10 ints. See the code example for my question.
void somefunc(int (*ap)[10])
{
int i = 5, j = 6;
...
Thanks. Is the temp pointer actually needed at all? Can I replace it with x[0]?
I found this code on the internet. Its purpose is to allocate a contiguous memory block for a two-dimensional dynamic array.
int** x;
int* temp;
x = (int**)malloc(dimension1_max *...