Search:

Type: Posts; User: jjohan

Page 1 of 4 1 2 3 4

Search: Search took 0.01 seconds.

  1. ok, thanks. new code: #include...

    ok, thanks.

    new code:



    #include <stdio.h>
    // Same as calender.c using pointers

    int main(void)
  2. Rewritten with arrays: int main(void) { ...

    Rewritten with arrays:



    int main(void)
    {
    int number_of_days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    char *week_days[7] = {"Monday", "Tuesday", "Wednesday",...
  3. Replies
    16
    Views
    5,150

    Ah ok I see. It's calloc() that does the trick.

    Ah ok I see. It's calloc() that does the trick.
  4. Replies
    6
    Views
    916

    Thank you.

    Thank you.
  5. Replies
    16
    Views
    5,150

    Then why does this work? Here a pointer to a...

    Then why does this work? Here a pointer to a local variable (new, in read_list) is returned too. Is the variable static?


    struct tlist
    {
    char t;
    struct tlist *rest;
    };

    struct tlist...
  6. Replies
    6
    Views
    916

    It's not a flame bait. I'm new as a c programmer...

    It's not a flame bait. I'm new as a c programmer and I started to wonder when I started to read about structs yesterday. Some fast googling seems to show that there's no big difference (except some...
  7. Replies
    6
    Views
    916

    Structs in C vs classes in C++

    Hi,

    What's the difference between a class in C++ and a struct in C?
    They seem to be very similar to each other. If they are so similar why can't OOP be used in C? Then what's the point of C++?
  8. Replies
    16
    Views
    5,150

    OK, Thanks for the advice Jim, I think I will do...

    OK, Thanks for the advice Jim, I think I will do that. Makes sense.
  9. Replies
    16
    Views
    5,150

    I want to know how to write my own calloc()...

    I want to know how to write my own calloc() version to learn how it works. I'm new to programming and at the moment I'm learning about pointers and dynamically allocated memory.
  10. Replies
    16
    Views
    5,150

    The compiler says: error: storage size of ‘mem’...

    The compiler says: error: storage size of ‘mem’ isn’t constant
    static int mem[n];

    How do I allocate dynamically then (without calloc or using low low level facilities that Laserlight suggested)?
  11. Replies
    16
    Views
    5,150

    But if mem is local, then why do the statements: ...

    But if mem is local, then why do the statements:


    printf("a[0]: %d\n", a[0]); printf("a[1]: %d\n", a[1]);
    printf("a[2]: %d\n", a[2]);

    in main print out what was assigned in...
  12. Replies
    16
    Views
    5,150

    OK, I think this will be a more complicated than...

    OK, I think this will be a more complicated than I can handle now, maybe in the future :)
  13. Replies
    16
    Views
    5,150

    Thanks. Was trying to write: static int...

    Thanks. Was trying to write:


    static int mem[n];

    in my_calloc() but didnt work.
    Not sure what you mean with initializing memory to zero.
  14. Replies
    16
    Views
    5,150

    My own calloc() not working.

    Hi,

    I'm trying to write my own version of the function calloc().
    Below is the code.
    Something goes wrong. The output when using my own calloc() is just random integers. The varibales in...
  15. Replies
    5
    Views
    858

    Thanks a lot Grumpy!

    Thanks a lot Grumpy!
  16. Replies
    5
    Views
    858

    The below code confuses me too. char...

    The below code confuses me too.


    char text[100] = "Hello world";
    char *ptr3;

    ptr3 = text;
    printf("%s\n", ptr3);
  17. Replies
    5
    Views
    858

    But if ptr[0] is a pointer shouldn't it contain...

    But if ptr[0] is a pointer shouldn't it contain an address to the string "Ptr text 1" and not the string itself? In the printf statement ptr[0] prints out the whole string "Ptr text 1" and not the...
  18. Replies
    5
    Views
    858

    why does this work? (array of pointers)

    Hi,

    I'm a bit confused here. The following code writes the strings in the pointer array ptr on the screen. I thought that ptr[15], contained 15 pointers. A pointer contains an address, so I though...
  19. Thanks. I will try to rewrite it.

    Thanks. I will try to rewrite it.
  20. Can this code be less messy if I use pointers/arrays?

    Hi,

    I think my program looks a bit messy. Can it be rewritten using pointers/arrays?
    Will that make the code more efficient? Will the code be more clean?
    The program takes a date (day of mont...
  21. Thread: '/0' in strings

    by jjohan
    Replies
    3
    Views
    634

    Ah ok, got it now, thanks!!

    Ah ok, got it now, thanks!!
  22. Thread: '/0' in strings

    by jjohan
    Replies
    3
    Views
    634

    '/0' in strings

    Hi,

    I wrote the following code:



    #include <stdio.h>


    int main(void)
  23. Replies
    2
    Views
    638

    Thank you!

    Thank you!
  24. Replies
    2
    Views
    638

    Point of function pointers

    Hi all,

    I'm wondering about the point of pointers to functions. When is it used?
    I saw the below example. It doesn't make sense to me. I mean we can easily write code that does the same without...
  25. Replies
    5
    Views
    1,181

    Good links ty.

    Good links ty.
Results 1 to 25 of 83
Page 1 of 4 1 2 3 4