ok, thanks.
new code:
#include <stdio.h>
// Same as calender.c using pointers
int main(void)
Type: Posts; User: jjohan
ok, thanks.
new code:
#include <stdio.h>
// Same as calender.c using pointers
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",...
Ah ok I see. It's calloc() that does the trick.
Thank you.
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...
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...
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++?
OK, Thanks for the advice Jim, I think I will do that. Makes sense.
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.
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)?
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...
OK, I think this will be a more complicated than I can handle now, maybe in the future :)
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.
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...
Thanks a lot Grumpy!
The below code confuses me too.
char text[100] = "Hello world";
char *ptr3;
ptr3 = text;
printf("%s\n", ptr3);
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...
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...
Thanks. I will try to rewrite it.
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...
Ah ok, got it now, thanks!!
Hi,
I wrote the following code:
#include <stdio.h>
int main(void)
Thank you!
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...
Good links ty.