Development > Coding
C Programming in Linux
hhbuur:
yes that made a difference, now it is compelling and the output is correct but there i still a problem.
--- Code: ---chapter2_1.c: In function ‘main’:
chapter2_1.c:23:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
sizeof(char),sizeof(int),sizeof(float));
^
chapter2_1.c:23:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
chapter2_1.c:23:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
chapter2_1.c:25:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
((STRINGSIZE*3) * sizeof(char)) + sizeof (int) + (2 * sizeof(float)));
--- End code ---
and to your question, i get my book from bookboom
--- Code: ---http://bookboon.com/
--- End code ---
gold_finger:
Bumping this for the OP.
Anyone here code in C that can help?
@hhbuur,
I have next to no experience, but I think I see one error. Correct this first, run program again and see if you still get other errors.
I could be wrong, but I believe that "DEFINE" should be "define" in this line:
--- Code: ---#define STRINGSIZE 256
--- End code ---
P.s. Does the book you're working from have a free version on the Internet? If yes, can you provide a link to the problem you're working on.
hhbuur:
hi i am trying to learn to program in c. and is using this guide. C Programming in Linux (c) David Haskins 2008
now at chapter2_1.c i got in to a problem the compelling will not run and I can not see what's wrong, is there som help to get?
--- Code: ---#include <stdio.h>
#DEFINE STRINGSIZE 256
int main(int argc, char*argv[])
{
char town[STRINGSIZE]="Guildford";
char county[STRINGSIZE]="Surrey";
char country[STRINGSIZE]="Great Britain";
int population=66773;
float latitude=51.238599;
float longitude=-0.566257;
printf("Town name:%s population:%d\n",town,population);
printf("County:%s\n",county);
printf("Country:%s\n",country);
printf("Location latitude:%f longitude: % f\n",latitude,longitude);
printf("char=%d byte int=%d bytes float=%d bytes\n",
sizeof(char),sizeof(int),sizeof(float));
printf("memory used:%d bytes\n",
((STRINGSIZE*3) * sizeof(char)) + sizeof (int) + (2 * sizeof(float)));
return 0;
--- End code ---
--- Code: ---Programming_In_Linux$ gcc -o data1 chapter2_1.c -lc
chapter2_1.c:7:2: error: invalid preprocessing directive #DEFINE
#DEFINE STRINGSIZE 256
^
chapter2_1.c: In function ‘main’:
chapter2_1.c:11:12: error: ‘STRINGSIZE’ undeclared (first use in this function)
char town[STRINGSIZE]="Guildford";
^
chapter2_1.c:11:12: note: each undeclared identifier is reported only once for each function it appears in
chapter2_1.c:22:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
sizeof(char),sizeof(int),sizeof(float));
^
chapter2_1.c:22:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
chapter2_1.c:22:2: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version