C · 783 B

Sample C file

An idiomatic C example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.c — first linesC
/* Sample C program — samplefiles.com */
#include <stdio.h>

typedef struct {
    int id;
    const char *name;
    double balance;
} Customer;

static int is_vip(const Customer *c) { return c->balance >= 10000.0; }

static double total_balance(const Customer *customers, size_t n) {
    double total = 0;
    for (size_t i = 0; i < n; i++) total += customers[i].balance;
    return total;
}

int main(void) {
    Customer customers[] = {{1, "Ada", 12500.0}, {2, "Grace", 830.5}, {3, "Linus", 10000.0}};
    size_t n = sizeof customers / sizeof customers[0];
    for (size_t i = 0; i < n; i++)
        printf("%-6s %10.2f %s\n", customers[i].name, customers[i].balance, is_vip(&customers[i]) ? "VIP" : "");
    printf("Total: %.2f\n", total_balance(customers, n));
    return 0;
}

File details

Size
783 B (783 bytes)
MIME type
text/x-c
SHA-256
c48ebbe00a18dedaa16ee1adf2ed820a1490a9061d1d1f2c99615073768e1035
MD5
caf2e59c2cdd6baa7424317ee1f592f6

Download from the command line

curl -L -o sample.c https://files.samplefiles.com/code/c/sample.c

Or check the download in your browser with the checksum calculator.

Same sample in other formats

Python · 620 BJavaScript · 642 BTypeScript · 733 BJSX · 596 BTSX · 788 BJava · 763 BKotlin · 541 BScala · 519 BC# · 689 BGo · 631 BRust · 771 BC header · 353 BC++ · 925 BSwift · 665 BDart · 639 BRuby · 461 BPHP · 749 BPerl · 524 BLua · 470 BR · 417 BJulia · 479 BHaskell · 578 BElixir · 675 BErlang · 719 BClojure · 488 BF# · 508 BZig · 762 BObjective-C · 861 BBash · 425 BPowerShell · 484 BAssembly · 610 BCSS · 645 BSCSS · 508 BVue · 611 BSvelte · 397 BDockerfile · 342 BMakefile · 346 BJupyter Notebook · 1.9 KBGroovy · 501 BFortran · 843 BPascal · 1 KBOCaml · 608 BNim · 616 BSolidity · 1.2 KBVerilog · 986 BVHDL · 920 BCommon Lisp · 751 BScheme · 747 BProlog · 574 BAda · 749 BD · 553 BElm · 985 BGleam · 697 BTcl · 414 BCoffeeScript · 475 BLess · 488 BSass · 510 BCMake · 692 BWebAssembly text (WAT) · 304 BWASM · 71 BJava class · 2.1 KBPYC · 1.2 KBSource map · 1.3 KB

Similar C files

FileSizeDetailsDownload
Large C file (about 10,000 lines)sample-10000-lines.c268 KB9,999 linesDownload