From BrycesWiki
Jump to: navigation, search

The C programming language is a programming language that must be compiled for each computer and is run via CLI.

Language Details

The C programming language is a low-level programming language that is capable of low-level formatting hard drive and goes through things in a procedural type manner, although programs can be broken into smaller pieces. A C program must be compiled on each computer, before it can run.

Code Example

Here is a sample of code that I have typed up in C. This is a fully functional program, but it makes use of functions that I have created myself, which are not included in this source code.

/* This program is a port of my Java program, ActualStorage.  
It takes the data you enter (e.g. size of device and unit of measure) and uses it to calculate 
how much usable space you have on secondary storage mediums.

Author: Bryce

#include <stdio.h> /* import standard input/output library */
#include "storage.h" /* import custom header file */

int main(void)

	float initial; /* declare variable to hold size */
	int unit; /* declare string variable to hold the unit */
	printf("Enter the size labelled on the box (without the unit):  "); /* display message asking for a numerical input, in order to specify size */

	scanf("%f", &initial); /* get user input */

	printf("Enter the unit of measure on the box.\n [1] KB, [2] MB, [3] GB, [4] TB, [5] PB, [6] EB, [7] ZB, [8] YB:  "); /* display message asking for 
        another numerical input, in order to specify unit */

	scanf("%d", &unit); /* get input */

	/* the following conditional statements check the inputted character and matches it to the correct formula */

	if (unit == 1)
	        printf("actaul storage in kilobytes:  %.2f\n", getKb(initial));

	if (unit == 2)
		printf("actual storage in megabytes:  %.2f\n", getMb(initial));

	if (unit == 3)
		printf("actual storage in gigabytes:  %.2f\n", getGb(initial));

	if (unit == 4)
		printf("actual storage in terabytes:  %.2f\n", getTb(initial));

	if (unit == 5)
		printf("actual storage in petabytes:  %.2f\n", getPb(initial));

	if (unit == 6)
		printf("actual storage in exabytes:  %.2f\n", getEb(initial));

	if (unit == 7)
		printf("actual storage in zettabytes:  %.2f\n", getZb(initial));

	if (unit == 8)
		printf("actual storage in yottabytes:  %.2f\n", getYb(initial));	

Yes, there is no input validation. This program assumes the user entered a valid entry.


As of the creation of this page, there is no page that can be identified as the official API for C.