February 24th, 2010

Iterations in PHP

No Comments, PHP, Scripting, by Steffy.

Hello, campers! Now then, let’s get stuck in. You can easily write a huuuuuuge article explaining iterations and how they differentiate, how to use them, etc, etc, etc. Same goes for objects and classes too. However articles like that are long winded, boring and mindless drivel but I’ll try to keep this as to the point as it gets with references to other sources where you can further your reading if that suits you…

Iterations

Some statements in programming and scripting languages are described as being iterative statements. These statements are structured and have conditions and terminating factors to control how many times the code in that block is executed. PHP has four major and commonly used iterative structures that we’ll look at now. These are:

  • ‘while’
  • ‘do … while’
  • ‘for’

More

Bookmark and Share

February 8th, 2010

Malloc

Comments Off, C, by JAG.

Malloc (or ‘memory allocation’) is an exceptionally useful tool in C that allows the programmer to create dynamically behaving arrays and structures within their program. So, how does it work?

If you imagine that when a program is made, it uses up ‘blocks’ of standard memory simply for it to run (while this is often minute, it’s still important to take into account). Memory is used upon compilation based on the number of instantiated variables within the code (ints, chars etc). This use of memory can be visualised as a grid with each block of memory available/used as squares within this grid. What malloc does is tell the program to ’set aside’ a given number of blocks of memory for later or current use.
More

Bookmark and Share

January 25th, 2010

Linked Lists

No Comments, C, by JAG.

A Linked List is a data structure that arranges data from a given input into a stored ‘list’. Each item in the list is known as a ‘node’.

Simple diagram displaying a Linked List

Each node within the list contains the set data as well as a ‘pointer’ to the next node within the list; hence ‘Linked List’.

Linked Lists in C utilise three things:

  1. malloc
  2. structs
  3. Pointers

Creating the structure

A C struct acts as a ‘node’ within the Linked List. One of the better ways to declare a C struct is to ‘typedef’ it as such:

#include <stdio.h>
#include <stdlib.h>

typedef struct my_struct_name {
    /* Declare the variables you want in each node */
    int i, j;
    char c;
    double d;

    /* Pointer for next node in list */
    struct my_struct_name *next_node;
} my_struct;

Note: The struct has, in essence, two names. Why? Well, the first name ‘my_struct_name’ refers to that ‘type’ of struct. The second name ‘my_struct’ refers to that specific struct. Also note that there is a pointer within the struct, of that type, which will be used to point to the next node within the list.

More

Bookmark and Share

December 26th, 2009

Array of Characters (Strings)

No Comments, C, Programming, by JAG.

Strings in C are handled differently to standard Java as there is no set ‘String’ library. The following example will show how to make a simple string in C89 C.

char array[5] = "Test\0";

Note: Every string ends in a ‘Null Terminator’ which is shown by a ‘\0′. If you do not add this at the end of your string, C will actually add one for you. However, this acts as an element within the array so if you don’t add it, make sure that the fixed size is one more than the number of characters (including white spaces).

Outputting the elements of a string in one consecutive line requires ‘%s’ in the output.

printf("My array is: %s", array);

Output:

My array is: Test

More

Bookmark and Share

December 16th, 2009

Create an array of Strings

No Comments, C, by JAG.

Creating a string in ANSI C is very simple, as it is simply an array of characters. However, creating an array that holds strings is a little bit more tricky. This utilises C’s malloc() library.

In order to create an array of strings, you first need two things. You need the actual array container itself, which is a pointer to a pointer of type ‘char’. You will also need a pointer to a char.

/* This is the array that currently has no set size */
char** string_array;

/* Note that no size has been set yet for this */
char* string;

Now that you have these two chars, you can use malloc() to designate blocks of memory, and add some text for the first string:

string = (char *)malloc(6 * sizeof(char));

/* strcpy() places text into the string */
strcpy(string, "Hello");

More

Bookmark and Share

December 10th, 2009

XHTML and Brief History

No Comments, XHTML, by ZesDa.

Overview

eXtensible HyperText Markup Laguage (acronym XHTML) is a growing Markup Language (based on the XML markup language itself) that extends that of SGML Markup Language currently well known as HTML (HyperText Markup Language) and defines how web pages are written and presented in Web Browsers. Whereas HTML maybe considered as a very flexible language to use when writing up websites, XHTML is based upon the XML standard whereby standard are more restrictive. This in turn requires pages to be written in a well formed and structured way in order to pass the online validation services offered.

More

Bookmark and Share

December 8th, 2009

Undergrad Developers

No Comments, General, by JAG.

The Developers section of the Undergraduate has now been put live.

This section is for showcasing current and past projects by the users of this website.

URL: http://www.the-undergraduate.co.uk/dev

Bookmark and Share

December 7th, 2009

PHP include() and require()

No Comments, PHP, Scripting, by Pyro.

This post will continue my work in explaining some of the basic in-built functions of PHP. This time around, I will take you through the include() and require() functions, and explain their similarities and differences and pros and cons respectively.
More

Bookmark and Share

December 7th, 2009

Inline CSS

No Comments, CSS, by JAG.

Some people are not aware that CSS can be used within HTML itself, other than just an ‘add-on’. It is very simple, and can often save a lot of space if only small style tweaks are required.

Example:

<div style="background: #CDCDCD; font-weight: bold;">
    Test.
</div>

Outcome:

Test.

It is very important to remember that the CSS can only lie within the style=”" element of a tag.

Bookmark and Share

December 7th, 2009

Interactivity with HTML Elements

No Comments, CSS, by JAG.

While there are many different aspects to CSS that will edit the looks of a webpage as a whole, there are several HTML elements that need to be looked at manually. Firstly we will look at DIV classes and id’s. These are two very important aspects of DIVs as they represent two different ways HTML will look at the DIV.

DIV Classes

A DIV class represents a non-unique identifier for the HTML code. What this means is that you may have multiple DIVs on one page with the same class. In essence, they belong to the same ‘family’, and share design traits (omitting dimensions and positions). In CSS, when looking at classes, they are represented with a full stop (‘.’).

More

Bookmark and Share

1 visitors online now
1 guests, 0 members
Max visitors today: 1 at 02:10 am UTC
This month: 7 at 03-03-2010 09:38 am UTC
This year: 20 at 02-19-2010 03:07 pm UTC
All time: 20 at 02-19-2010 03:07 pm UTC