Search:

Type: Posts; User: kkk

Page 1 of 2 1 2

Search: Search took 0.00 seconds.

  1. Replies
    2
    Views
    1,680

    Program running slower after optimization?

    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 -...
  2. Replies
    4
    Views
    1,363

    I tried running the code outside my IDE and it...

    I tried running the code outside my IDE and it worked. So the problem is in the IDE!
  3. Replies
    4
    Views
    1,363

    Yet another EOF issue

    Hello,

    I tried the following code to experiment with EOF:




    int c;

    while(1)
  4. Replies
    11
    Views
    3,288

    Thanks for your valuable post, I now get it!...

    Thanks for your valuable post, I now get it! Perfect! Thanks again!
  5. Replies
    11
    Views
    3,288

    Just read it. What I don't get is that EOF works...

    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...
  6. Replies
    11
    Views
    3,288

    How is "entering" EOF supposed to work in...

    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?
    ...
  7. Replies
    11
    Views
    3,288

    If I enter some text and press CTRL+D twice, the...

    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...
  8. Replies
    11
    Views
    3,288

    *nix (Mac OS X 10.7 with XCode 4)

    *nix (Mac OS X 10.7 with XCode 4)
  9. Replies
    11
    Views
    3,288

    K & R Chapter 1.9 getline problem

    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...
  10. Replies
    18
    Views
    2,594

    Why would one want to do that in the first place?...

    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"...
  11. Replies
    18
    Views
    2,594

    K & R exercise - which code would you prefer?

    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...
  12. Replies
    1
    Views
    825

    Binary search - two functions

    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,...
  13. Thread: fgets and scanf

    by kkk
    Replies
    10
    Views
    3,794

    Yep, that's what I overlooked, thanks. And why...

    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...
  14. Thread: fgets and scanf

    by kkk
    Replies
    10
    Views
    3,794

    #include #include ...

    #include <stdio.h>
    #include <stdlib.h>

    #define MAXSIZE 5

    char numbers[MAXSIZE + 1];

    int myatoi(const char *str)
    {
    int val = 0;
  15. Thread: fgets and scanf

    by kkk
    Replies
    10
    Views
    3,794

    I did consult the man pages and I did try to look...

    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...
  16. Thread: fgets and scanf

    by kkk
    Replies
    10
    Views
    3,794

    fgets and scanf

    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...
  17. Replies
    6
    Views
    1,697

    A mistake in the K & R bible?

    Hello,

    the following excerpt is taken from "The C Programming Language" by K & R:


    main()
    {
    int c;
    while ((c = getchar()) != EOF)
    putchar(c);
  18. Replies
    2
    Views
    8,758

    Convert seconds to hours, minutes and seconds

    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...
  19. Thread: Bit output

    by kkk
    Replies
    5
    Views
    1,125

    Yes, incrementing it by one each time I increment...

    Yes, incrementing it by one each time I increment the buffer pointer.
  20. Thread: Bit output

    by kkk
    Replies
    5
    Views
    1,125

    Bit output

    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...
  21. Thread: Ternary operator

    by kkk
    Replies
    12
    Views
    4,073

    Ternary operator

    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...
  22. Replies
    1
    Views
    1,630

    Accessing array members

    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,...
  23. Thread: Dereferencing

    by kkk
    Replies
    1
    Views
    975

    Dereferencing

    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;
    ...
  24. Replies
    4
    Views
    1,877

    Thanks. Is the temp pointer actually needed at...

    Thanks. Is the temp pointer actually needed at all? Can I replace it with x[0]?
  25. Replies
    4
    Views
    1,877

    Freeing dynamically allocated memory

    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 *...
Results 1 to 25 of 32
Page 1 of 2 1 2