Stack1's Posts
Nairaland Forum › Stack1's Profile › Stack1's Posts
1 2 3 4 5 6 7 8 9 10 11 12 (of 12 pages)
interesting comments, anyways lets proceed most programs require ways of accepting input to work on or process, in the case of C they are library functions to allow reading and manipulation of characters from STDIN (standard input - usually your screen), files on disk, or say from network ports etc, we would be looking at several programs that accept input from the keyboard, does some manipulations on them and outputs the result |
anyone following, do i proceed? |
Sibrah:Well said, though the Ram could be higher b'cuz IDE's of today and even browser's could eat up a lot of ram |
We could build ours, 'm in to help with coding and stuff, but who go purchase VPS ![]() |
satelliteDISH:Thatss not correct sir, you can actually read and understand any programming language on your own, while its not going to be easy many have done it and are still doing it, I never attended a programming school and i code in multiple languages.. |
look here http://www.mysqltutorial.org/ |
In the previous example, notice that within the opening tag of the H1 element we wrote id='txt1' This is called an attribute, attributes provide additional information or functionality to an element, in the case of the example the attribute is called the id attribute and it can be applied to all HTML elements, attrubutes come in the form attributeName="attribute val" standard attributes include 1. title -- which display's as a tool-tip when you mouse-over an element 2. id 3. name 4 class 5. href -- used in links 6. src used in image and other tags In the previous example the <style> tag represents the start of a style section in the document. What we put within the opening and closing style tags are known as style rules, these rules are defined by the CSS language In our example we have the text
the text #txt1 is known as a selector and is used to target elements in the page note that txt1 is the same as the id attribute of our <h1> element in the page. In CSS when a selector starts with #, it means match an element with the id that follows the # character so in our example #txt1 matches the h1 element and the statements enclosed in {} after the selector are applied to the h1 element the sentence font-size: 6em is called a style declaration and consists of two parts font-size is the style property (of which they are numerous and 6em is called the style value. in this case the 6em changes the size of the text,. Sizes and length in CSS can be represented using various units including px (pixels), em (1em is usually 16px) ,pt (points used mostly for text), also inches, cm and others can be used |
HTML tags describe the structure of a document but are not very good for styling and presentation, thats where CSS (Cascading Style Sheets) come in CSS enables us add colors, fonts, spacing, control positioning and many other things on our HTML Elements. CSS is usually added to an HTML document by linking an external CSS file (called a style sheet). It can however also be added to the head section of the document or in-line as attributes on elements Lets see an example <!DOCTYPE html> <html> <head> <title>CSS Intro</title> <!-- start of CSS tag in head section --> <style> #txt1{ font-size :6em; color :red } </style> <!-- closing the style tag --> </head> <body> <h1 id='txt1'> This text is controlled with CSS </h1> </body> </html> |
now lets look at another example showing off more HTML tags
|
do we proceed? |
Explanation The last program prints a table of Celsius values from converted from Fahrenheit. You might have noticed some text surrounded by /* */ this is called a comment, in programs comments are used to document and explain parts of your program C has both multi-line comments which start with /* and end only when the pair */ is found single line comments start with // and end on the same line, the statement includes the header for the standard Input/Output library next the main function starts, the int in front of main tells us this functions is meant to return an int and the void means it doesn't take any arguments the line int farh, celsius, upper, lower, step; declares 5 integer variables, then we assign values to four of the variables with the statements
the -while- statement is used to create a loop that executes repeatedly, until the value of expression becomes equal to zero in our example
means while the value of the farh variable is less then equal to the value of the upper variable the statments within the body of the while loop should keep executing to calculate our celsius value we use use the statement
which uses the common formular °C = (°F - 32) × 5/9, but note we didnt do 5/9 this is because we declared our variables as integer, and if we had done
our answer would have been fractional and int's cant store fractions, so the answer wouldn't (and actually isnt accurate) Exercise Try and rewite the program declaring the celcius and farh variables as float's |
lets jump into more examples... Type this in a new C file, save then compile it
|
... still on variables again we have the types for decimal input 1. float - holds a value between 1.2E-38 to 3.4E+38 and is precise to 6 decimal places 2. double - holds a value between 2.3E-308 to 1.7E+308 and is precise to 15 decimal places 3. long double - usually the same as floats or could hold between 3.4E-4932 to 1.1E+4932 Floats and doubles are much more complex to discuss in detail so we skip that for now programs usually need character input so C has the char type 1. char - holds 1 byte (usually a letter) with the ASCII range -128 to 128 and if its unsigned its range is 0-255 ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort. (cited from wikipedia) Here's a link to a good ASCII table that shows you how charcters map to ASCII numbers http://www.asciitable.com/
|
..more about variables the statement int age; is called a declaration and composes of two parts 1. the type which is int, and the name of the variable (called the identifier) A variable that is simply declared doesn't have any valued stored in it, however later on in the program we might decide to associate a value with the variable. e.g age = 32; now this is called an assignment as we have assigned a value to the variable, and the variable can now be used in the program, assignmets can also be done at the point of declaration e.g
trying to access variables that haven't been assigned a value (or that haven't been initialized is a common source of program errors) |
Ok so lets move on VARIABLES In a C program (and in probably all programming languages), your program usually does some form of calculation or manipulation or transformation on data, this data could be predefined (stored or hard-coded in the program) of it might be inputted by the user or gotten from other sources while the program is running, such data that is used to provide information to a program are called variables. Creating a variable in C is ease, variables take the form
for variable type we spoecify the type that tells us more about what we intend to store in the variable. lets look at the basic C types we have the a integer (or number types), this include int (which stands for integer), the integer type allows us store numbers in our programs, you could declare an integer variable as such
Originally the range of numbers the int type could hold varied depending on the CPU architecture. Nowadays actually you can expect an integer to hold any value between -2147483647 - 1 to -2147483647 (i.e it can hold upto 32 bits of data), this also shows us that the standard int type is signed and can hold negative numbers. If you do not want your variable to hold negative values declare it using the unsigned modifier, an example is
unsigned integers can hold a value between 0 and 4294967295, They are other modifiers one cane use with int 1. use short to clip the value that can be stored in the variable to -32768 - 32767, and use unsigned short to store values from 0 - 65535 2. we have long int declared (long int) in most compilers nowadays though the allowed values is the same as int 3. long long int, capable of holding values between -9223372036854775807 - 1 to -9223372036854775807 and unsigned long long int which holds 0 to 18,446,744,073,709,551,615 so here are the different ways to declare an integer
|
Yteflon:Thanks bro, but that might still take sometime. Looking to cover HTML/CSS to a good level first |
..more in a few hours |
Ok i havent talked about how you'll turn your program text (a.k.a sourcecode into a working program you can run). C is a compiled language (though interpreters exist) and traditionally after writing your C code in a source file and saving it, you compile it by running the compiler on your command line or shell. We would actually still get to that but for now such complexities are best avoided. since we are using the codeblocks IDE, to compile your code simply type Ctrl+F9 -- to compile only Ctrl+F10 -- to run F9 to -- to compile and run in one step while compiling you might get errors that have being detected in your code, usually the first few (<5) errors should pinpoint where exactly in your code the mistake was made so you could edit and correct them |
As said before, the printf function is used to print or output text to the standard output (usually the screen but could be other stuffs like network ports). In printf sequence of characters are enclosed in double quotes e.g. "Hello world" and such quoted characters are known as string constants The sequence \n is known as a new line character and what it does is to print a new line so the text following it starts on a new line To illustrate the use of \n edit the printf statements in the previous example to
you'll notice --Shakespeare starts on a new line |
questions/comments before we proceed?? |
C programs are usually just a collection of functions. A functions (called routines or procedures in some language) can be seen as a series of statements and is given a name, functions are usually meant to perform just one *function. The standard structure of a function is something like..
more on functions later... Every C program must have (ok not strictly must) have a function called main, which acts as the entry and exit point of your program In our example above the main function just prints the Line Hello World using the printf function. The printf function is from the standard Input/Output Library which we have included with the statement
|
C is a very compact language and doesn't include many features or operators and most useful things you'll be doing would be provided by using pre-written code that comes packaged with a standard C compiler this kind of pre-written code are called libraries. In the code above the line
is called an include directive, stdio (for standard io) is a standard C library that provides utilities (lets call them functions) for various input output operations. Libraries in C are included in a project using the libraries header file, header files end in .h so stdio.h is the header file for the Standard Input Library. |
if you have completed all the previous steps then its time start coding create a new file in codeblocks and make sure it is saved with .c extension then type in the following (please do not copy and paste always try to type in every code)
|
I'm going to introduce CSS Cascading Style Sheets early in this series because of how closely its normally integrated with HTML, please let your comments / questions roll in |
dhtml18:oops, didnt mean to be rude the differences between C and C++ are not subtle, so its usually necessary to have some working knowledge of both to really grasp their diffrences. My apologies pls, i'm kinda multitasking on various stuff right now so i could explain better |
Lets talk about headings. Heading tags are tags used to specify the header of various content in a page, and more importantly are used by search engines to index the structure of your page. There are six different heading tags, the difference between them is actually just the size of the text they produce Edit the body section of your page and add the following lines then save and refresh your browser
|
The title tag as the name implies sets the title of the page, so modify the title content as desired Note that all content that affects what is visible on a webpage goes inside the <body></body> As i said earlier tags usually come in pairs e.g
The first tag is called the opening tag while the second (the one with the slash /) is called the closing tag. Tags that come in pairs are normally meant to have content within the opening and closing tags some tags however are called empty tags and are not closed, they also do not have content e.g.
|
install and launch codeblocks and go to settings menu and select compiler select GCC compiler from the list and go to Toolchain executables tab, modify the compilers installation directory to point to the directory where you unpacked the mingw compiler you downloaded, and modify other tools path as needed, see the attached picture to get an idea of what i mean
|
I am going to assume at this point you have downloaded codeblocks and the GCC/mingw compliler, and aslo you have extracted the compiler archive to your C: directory |
Html is made up of tags. A tag is literally anything in an Html document surrounded by angle braces i.e <>. In the example above <html> is a tag <title> is a tag <p> is a tag .... tags usually come in pairs, an opening and a closing tag, when creating web-pages the <html> tag is usually the ones that surrounds (or encloses) all other tags so you normally start out with something like
comments are also allowed in html to enter a comment use <!-- comment text --> as i did above. Comments do not get parsed/interpreted by the browser |
dhtml18:Bro for now, please lets just focus on the tutorials, differences would come later |
