LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C Programming in Linux
#4
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;
}


I compiled it with this code:

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


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


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


P.s.  Is this line of output what you were expecting it to be?
Code:
char=1 byte int=4 bytes float=4 bytes
Try Linux Beginner Search Engine for answers to Linux questions.
Reply


Messages In This Thread
C Programming in Linux - by hhbuur - 04-14-2015, 11:16 AM
Re: C Programming in Linux - by gold_finger - 04-18-2015, 02:46 AM
Re: C Programming in Linux - by hhbuur - 04-18-2015, 10:29 AM
Re: C Programming in Linux - by gold_finger - 04-18-2015, 01:55 PM
Re: C Programming in Linux - by hhbuur - 04-19-2015, 12:05 PM
Re: C Programming in Linux - by gold_finger - 04-19-2015, 02:24 PM
Re: C Programming in Linux - by avj - 04-19-2015, 04:54 PM
Re: C Programming in Linux - by hhbuur - 04-21-2015, 09:27 AM

Forum Jump:


Users browsing this thread: 5 Guest(s)