Development > Coding

C Programming in Linux

(1/2) > >>

hhbuur:
i haw the } on the last line. I will continue with exercises and see how it's going to proceed ;)

avj:
It appears that you missed the } on the very last line.

gold_finger:

--- Quote from: hhbuur on April 19, 2015, 08:05:24 AM ---i get the same outputs as before no mater witch of yours variations I try, can there may be a differences in the versions of gcc, makes the difference in the output, the version i haw install is 4:4.8.2-1ubuntu6 , and your ? I get the same result as in the book

--- End quote ---

I used 32-bit LL 2.2 and the gcc package is the same version# as yours.


I just downloaded the book so I could see exactly what the exercise was.  Aside from making the correction from "DEFINE" to "define", it all looks the same as what I input and the output from mine matches that of the book (with no error messages).  In all likelihood, if you're still getting error messages, you have a typo somewhere or a missed character.  Double-check what you have.

From what you've posted, the only other thing I noticed is that you had a space between "sizeof" and "(int)" on this line:

--- Code: ---    printf("memory used:%d bytes\n",
        ((STRINGSIZE*3) * sizeof(char)) + sizeof (int) + (2 * sizeof(float)));
--- End code ---

However, I purposely ran the code with that space also and it did not give me an error -- so I doubt that is the source of your problem.

Only other thing that  I can think of is that you made the change from "DEFINE" to "define", saved the document, but did not re-compile the program with the new change.  You need to save the change in the text file, then re-compile it before running the program again.

Aside from that, I'm clueless as to why it's not working for you.

hhbuur:
i get the same outputs as before no mater witch of yours variations I try, can there may be a differences in the versions of gcc, makes the difference in the output, the version i haw install is 4:4.8.2-1ubuntu6 , and your ? I get the same result as in the book

gold_finger:
I ran a test of your code in VirtualBox install of LL and I did not get the errors you are reporting.

I called the program "sample.c" and saved it to the Desktop.  Here is the exact code I used:


--- 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 ---


I compiled it with this code:


--- Code: ---homey@homey-VirtualBox:~/Desktop$ gcc sample.c -o sample
--- End code ---


Ran it with this command and got the following output:


--- Code: ---homey@homey-VirtualBox:~/Desktop$ ./sample
Town name:Guildford population:66773
County:Surrey
Country:Great Britain
Location latitude:51.238598 longitude: -0.566257
char=1 byte int=4 bytes float=4 bytes
memory used:780 bytes
--- End code ---


Compiled it again with the following command to match what you did, ran program again and got the same output as above:


--- Code: ---homey@homey-VirtualBox:~/Desktop$ gcc -o sample sample.c -lc
homey@homey-VirtualBox:~/Desktop$ ./sample
Town name:Guildford population:66773
County:Surrey
Country:Great Britain
Location latitude:51.238598 longitude: -0.566257
char=1 byte int=4 bytes float=4 bytes
memory used:780 bytes
--- End code ---


P.s.  Is this line of output what you were expecting it to be?

--- Code: ---char=1 byte int=4 bytes float=4 bytes
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version