₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,052 members, 8,420,072 topics. Date: Thursday, 04 June 2026 at 10:41 AM

Toggle theme

Stack1's Posts

Nairaland ForumStack1's ProfileStack1's Posts

1 2 3 4 5 6 7 8 9 10 11 12 (of 12 pages)

ProgrammingRe: Lets Learn C by stack1(op): 12:24am On Jul 25, 2016
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
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 12:17am On Jul 25, 2016
anyone following, do i proceed?
ProgrammingRe: What Are The Best Laptops For Programmers And Hackers?! by stack1(m): 3:04am On Jul 24, 2016
Sibrah:
My idea of the best Laptop for programming and hacking is a laptop with about 4gb RAM, average Core i5 or i3 processor, a terrific battery(double cell reinforcement battery to last at least 8hrs on full charge) and a good virtual Machine to help test programs on Low spec virtual machines. I recommended that amount of RAM/Processor power becos RAM and Processor consume more power as according to their size. The key thing is good battery life and good virtual environment to test programs on older and variety of OS.
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
ProgrammingRe: For Real Developers by stack1(m): 3:00am On Jul 24, 2016
We could build ours, 'm in to help with coding and stuff, but who go purchase VPShuh wink
ProgrammingRe: I Want To Teach Myself Php And HTML, What Are The Programming Softwares I Can St by stack1(m): 2:50am On Jul 24, 2016
satelliteDISH:
U cannot read and understand PHP on your own. Go to a competent ict school and enrol.

But if U want to learn HTML on your own, U can start with this e-book "HTML for Dummies".

Download it online or purchase it on their site. It is $27.
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..
ProgrammingRe: Php Coders Help by stack1(m): 2:47am On Jul 24, 2016
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 2:42am On Jul 24, 2016
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

#txt1{
font-size :6em;
color :red

}


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
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 1:42am On Jul 24, 2016
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>
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 1:37am On Jul 24, 2016
now lets look at another example showing off more HTML tags


<!DOCTYPE html>
<html>
<head>
<title>Tag soup</title>
</head>
<body>

<p>This is a paragraph.</p>
<h1> This is a header </h1>

<b> This text is bold </b>

<i> this text is italicized </i>

<blockquote>
This text is inside a blockquote tag. A blockquote defines a section that is quoted from another source or diffrerent from the normal flow of the document
</blockquote>



</body>
</html>

ProgrammingRe: Lets Learn C by stack1(op): 1:21am On Jul 24, 2016
do we proceed?
ProgrammingRe: Lets Learn C by stack1(op):
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
 
#include <stdio.h>
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

lower = 0;
upper = 300;
step = 20;
farh = lower;



the -while- statement is used to create a loop that executes repeatedly, until the value of expression becomes equal to zero
in our example

while(farh <= upper)


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


celcius = 5* (farh-32)/9


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

celcius = 5/9 * (farh-32)


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
ProgrammingRe: Lets Learn C by stack1(op): 12:58am On Jul 24, 2016
lets jump into more examples...
Type this in a new C file, save then compile it


/*
* simple farenheit to celsius converter
*/

#include <stdio.h>

int main(void)
{
int farh, celsius, upper, lower, step;

lower = 0;
upper = 300;
step = 20;
farh = lower;


//print the table header
printf("Fahrenheit \t \t Celsius\n" );

while(farh <= upper)
{
celsius = 5* (farh-32)/9 ;


printf("%3d \t \t \t %6d\n", farh, celsius);

farh += step;

}

getchar();

return 0;
}


ProgrammingRe: Lets Learn C by stack1(op): 12:49am On Jul 24, 2016
... 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/


in C storing a letter such as

char letter = 'a';

is the same as storing its ascii equivalent
char letter = 97;

ProgrammingRe: Lets Learn C by stack1(op): 12:40am On Jul 24, 2016
..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

int width = 40;
int height = 25;

then say we wanted to add both values we simply do

weight + height



trying to access variables that haven't been assigned a value (or that haven't been initialized is a common source of program errors)
ProgrammingRe: Lets Learn C by stack1(op): 12:22am On Jul 24, 2016
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

variable-type variable-name;


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

int age;
int date_of_birth;


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 int age;

or just
unsigned date_of_birth;



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


int number
long int number
unsigned int number (or just unsigned number)

short int number (or just short number)
unsigned short int ( or just unsigned short)

long long int ( or just long long)
unsigned long long int ( or unsigned long long)
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 7:18pm On Jul 23, 2016
Yteflon:
keep it up... waiting on u on JavaScript
Thanks bro, but that might still take sometime. Looking to cover HTML/CSS to a good level first
ProgrammingRe: Lets Learn C by stack1(op): 7:15pm On Jul 23, 2016
..more in a few hours
ProgrammingRe: Lets Learn C by stack1(op): 7:15pm On Jul 23, 2016
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
ProgrammingRe: Lets Learn C by stack1(op): 7:08pm On Jul 23, 2016
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


printf(" brevity is the soul of wit. \n --Shakespeare\n" );






you'll notice --Shakespeare starts on a new line
ProgrammingRe: Lets Learn C by stack1(op): 6:48pm On Jul 23, 2016
questions/comments before we proceed??
ProgrammingRe: Lets Learn C by stack1(op): 6:48pm On Jul 23, 2016
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..


return-type function-name( function-arguments) {

function-statements

}


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

#include <stdio.h>
ProgrammingRe: Lets Learn C by stack1(op): 6:30pm On Jul 23, 2016
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


#include <stdio.h>


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.
ProgrammingRe: Lets Learn C by stack1(op): 6:16pm On Jul 23, 2016
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)


#include <stdio.h>
int main()
{
printf("hello, world\n" );
getchar();
}

ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op):
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
ProgrammingRe: Lets Learn C by stack1(op): 5:59pm On Jul 23, 2016
dhtml18:
That was out-rightly rude, but it is alright, i hereby step out of this thread permanently.
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
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 5:57pm On Jul 23, 2016
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


<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 5:51pm On Jul 23, 2016
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


<body></body
<video></video>
<p></p>


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.



<br /> --line break tag
<hr /> -- horizontal rule
<img /> -- image tag

ProgrammingRe: Lets Learn C by stack1(op): 5:43pm On Jul 23, 2016
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

ProgrammingRe: Lets Learn C by stack1(op): 5:38pm On Jul 23, 2016
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
ProgrammingRe: Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql by stack1(op): 5:33pm On Jul 23, 2016
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



<!DOCTYPE html> <!-- doctype declaration -->

<html>

..other tags go here

</html>


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
ProgrammingRe: Lets Learn C by stack1(op): 5:27pm On Jul 23, 2016
dhtml18:
Please tell us difference between C, C++ and not C#?
Bro for now, please lets just focus on the tutorials, differences would come later

1 2 3 4 5 6 7 8 9 10 11 12 (of 12 pages)