Hi folks,
In a book I'm reading about C, I have come across a program that was trying to demonstrate basically the same thing that King Mir was teaching me in another thread, how different types of data are alloted the same amount of memory, char, int, float etc...
The context of this program was to show that the string has the same amount of memory regardless of what one puts in scanf. However I'm getting errors when I try to compile that I don't understand. I have read over the program in the book character by character about ten times now to make sure I typed it right, and as far as I can tell I typed it verbatim, anyways, here is the program + the errors:
Code:
/* praise2.c */
#include <stdio.h>
#include <string.h>
#define PRAISE "What a super marvelous name!"
int main()
{
char name[40];
printf("\nWhat's your name?\n");
scanf("%s", name);
printf("\nHello, %s. %s\n", name, PRAISE);
printf("\nYour name of %d letters occupies %d memory cells.\n", strlen(name), sizeof name);
printf("\nThe phrase of praise has %d letters ", strlen(PRAISE));
printf("\nand occupies %d memory cells.\n", sizeof PRAISE);
return 0;
}
And the compiler errors:
praise2.c: In function 'main':
praise2.c:14:2: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t' [-Wformat]
praise2.c:14:2: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int' [-Wformat]
praise2.c:15:2: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t' [-Wformat]
praise2.c:16:2: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [-Wformat]
I have no idea what size_t is nor was I aware that I put a long unsigned int in this program... any ideas?