From: Subject: Date: Mon, 25 Feb 2008 12:17:35 +0200 MIME-Version: 1.0 Content-Type: multipart/related; type="text/html"; boundary="----=_NextPart_000_0000_01C877A8.678464C0" X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 This is a multi-part message in MIME format. ------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: text/html; charset="windows-1254" Content-Transfer-Encoding: quoted-printable Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/onlineCourseNotes/book_as_printable.php

 

CMPE 150 Introduction to Computing
(C Programming=20 Language)
Lecture Notes

by
=C7igdem G=FCnd=FCz
online conversion
Da=F0han Din=E7

1. brief introduction

  • A computer is:=20
    1. a device for counting and computing=20
    2. a machine that can process data
  • A computer can not reason as we do. To perform some task by using=20 computers, we need to to tell all necessary steps (in terms of = instructions)=20 to perform it. The list of instructions is called a program=20
  • These instructions are given by using a programming = language. But a=20 computer can only understand 0 and 1's (actually volts). Therefore the = instructions must be written in the form of binary strings or = translated into=20 binary strings.=20
  • Programming languages can be:=20
    1. Machine language: It is a native tongue of a computer. Each = instructions=20 is a binary string.=20
    2. High level languages: They are English like languages, eg. C, = Pascal,=20 Fortran. Each language has its own standard and its own predefined=20 instructions. Most of them have libraries that are coded by other = people.=20 High level language instructions are translated in machine language = by a=20 compiler. All necessary steps to form an executable program from the = instructions written in a high level language is given in Figure = 1.

      Figure 1: The steps of forming an executable program from a = source=20 file.

  • Software development=20
    1. State the problem=20
    2. Analyze it (identify inputs and outputs)=20
    3. Design an algorithm, i.e., specify the list of steps=20
    4. Implement the steps by using a programming language=20
    5. Compile and execute the program.=20
    6. Test it whether your program (its executable) works correctly or = not.=20

2. introduction to C

  1. Hello World example=20

    Suppose the program which displays "Hello World" message on the=20 screen


    #include <stdio.h>
    int main(){
    	printf("Hello World\n");
    	anykey();
    	return 0;
    }
    

    main()

    C program contains one or more functions (programming blocks). = Functions=20 contain statements (one or more) that specify the operations to be = done. Every=20 C program contains a function called main. Some words in C are = reserved for=20 specific purposes like main, if, while, for, int, char, ... Note that = C is a=20 case sensitive language, e.g main is not the same with mAiN. =

    { }

    They (curly brackets) show the start and end of a block = respectively.=20 Blocks (compound statements) are used to group statements together. In = the=20 above example, the curly brackets indicate the beginning and the end = point of=20 the function main.

    printf("Hello World\n");

    It is a statement that dispays the text enclosed in double quotes. = Note=20 that each statement must end with a semicolon. Some characters like = newline,=20 horizontal tab, etc. are represented with backslash (\) and some = special=20 characters together. e.g., \n is a newline character, \t is a = horizontal tab=20 character, etc. We call \ as an escape character. =

    #include<...>

    It tells the compiler to include a library defined before. If you = want to=20 use any standard library function, you must declare its name in = between <=20 and >.

    #include<stdio.h>

    It includes stdio.h library which includes standard input/output = (screen,=20 keyboard, file system, etc) functions, e.g., printf(), scanf(), = getchar(),=20 etc. In the above example, we need a library that allows the program = to=20 interact with the I/O devices for using printf() function.

  2. Summation of two integers=20

    Suppose a program that takes two integers fromt he user and = displays their=20 sum on the screen


    #include =
    <stdio.h>
    /* This is the second program */
    int main(){
    	int no1, no2, sum;
    	printf("Enter the numbers: ");
    	scanf("%d%d",&no1,&no2);
    	sum =3D no1 + no2;
    	printf("The sum is %d\n",sum);
    	anykey();
    	return 0;
    }
    

    /* ... */

    It indicates a comment. All things (comments) in between /* and */ = are=20 ignored by C compiler, i.e., they are not translated into the machine=20 language. They are only for readability, documentation and information = for=20 code readers. Be careful that a comment must begin with /* and ends = with */ (*=20 and / must be consecutive, there is no gap between them). Note that = comments=20 can be extended more than one lines. So the following comment is also=20 valid.

    /* Thi
    s is the
    seco
    nd program
    */

    ; indicates the end of the statements, there may be mnore than one=20 statement in a line as well as a statement can be seperated into = multiple=20 lines. For example all examples below are valid = statements.

    int no1,
    no2, sum; printf("enter the numbers:");
    scanf("%d%d",
    &no1,
    &no2);
    sum =3D no1 +
    no2;printf("The sum is %d\n",sum);return 0;

    Note that some characters like blank, tab, return are ignored by = the=20 compiler. Therefore you can put any of these in between statements, = after=20 comma, plus sign, etc. But you can not put them in between print, sum = or the=20 string (text) in double quote. The following examples are all = invalid.

    in			/* since you seperate int */
    t no1, no2, sum;		=09
    prin			/* since you seperate printf */
    tf("Enter numbers:");
    scanf("%d%d",&n		/* since you seperate variable name no1 */
    o1,&no2);
    printf("The su		/* since you seperate the text in double quote */
    m is %d\n",sum)ret		/* since you seperate return */
    urn 0;

    In this example we need to store the values of the first and the = second=20 number to compute their summation and the value of this summation to = display=20 it. Therefore we need somewhere in the computer to store their values. = They=20 are kept in the memory. The memory consists of an ordered sequence of = storage=20 locations (memory cells). Each memory cell has an unique address = associated=20 with it. Memory cells are the collection of smaller units called a = byte

    int no1, no2, sum;

    This is a declaration statement and no1, no2 and sum are called = a=20 variable. Variables are used to store values during the = computation. To=20 keep the values of variables, some memory place must be allocated. = Declaration=20 statement associates a memory cell for each variable name and when you = want to=20 access a variable, just call it with its name and the program knows in = which=20 address it is stored. But you must declare variables before using = them.

    For each variable, we must indicate its type. In our example int = indicates=20 the integer data type (there are also other data types in Q. In = declaration=20 you must first specify the data type than you must list a single = variable name=20 or list of them. The variables in a list must be separated with = commas. The=20 following declarations are all valid. Also note that each declaration=20 statement ends with a semicolon.

    int a, b, sum;
    int d;
    int one,
    two, three;
    scanf("%d%d",&no1,&no2);

    It reads a value from the standard input device (the default device = is=20 keyboard). While the program executes this statement, it waits the = user to=20 enter a value and press a return key (enter) for sending it to the = computer.=20 If you use scanf() function, you must include stdio.h library to your=20 program.

    %d (conversion specifier) indicates that an integer value will be = read into=20 the specified variable. In our example there are two %d' s, thus two = integer=20 values will be read into the variables nol and no2 which are specified = after=20 double quote and separated by commas.

    & is an address operator. For that moment, you must just know = that it=20 must be used before the name of a variable in the scanf() function. = The=20 following statements perform the same task with the above = scanf().

    scanf ("%d",&no1);
    scanf ("%d",&no2);
    
    sum =3D not + no2;

    It is an assignment statement. First the right hand side (RHS) of = the=20 statement is computed, then the value of the RHS is assigned to the = left hand=20 side (LHS). In our example nol and no2 are added and the value of = summation is=20 stored in variable sum.

    printf("The sum is %d\n",sum);

    We know that it displays the text between double quote on the = screen.=20 Besides this, %d indicates that an integer value is written on the = screen. In=20 our case the value of the variable sum is written on the screen. We = can also=20 write the values of constants, variables, combination of constants and = variables. It is also possible to write more than one value. All of = the=20 following formats are valid:

    printf("The sum is %d", sum);
    printf("The sum is %d",3);
    printf("The sum is %d",a + b);
    printf("The sum is %d", sum + a * 3);
    printf("When we add %d to %d, we get %d",a,B,a+B);
    printf("add 9 to %d and get %d",number,number+9);
    return 0;

    Every function should return a value unless the otherwise is = specified. It=20 gives information to the caller of a function. We will see it later in = detail.=20

3. data types

  1. Integers=20

    There are different types of integers each of which differs in = size. ANSI=20 standard determines the minimum size for each, but the exact size = depends on=20 your computer. It can be classified into three according to their = sizes.

    1. short int (at least 16 bits)=20
    2. int (either short or long)=20
    3. long int (at least 32 bits)

    It is also possible to classify them as:

    1. signed int: both positive and negative values can be stored. = When you=20 use int, it means signed int in default.=20
    2. 2. unsigned int: only nonnegative values can be kept. In the=20 representation of an integer, most significant bit is used as the = part of a=20 number rather than the sign bit.

    Note that:

    • int can be omitted in short int, long int, etc.=20
    • Be careful to understand the limitations of data types. If = overflow=20 exists, i.e., if a value is too big to fit into the memory location, = ANSI=20 standard says that behavior is undefined under such circumstances = which=20 means that anything might happen. Consider an integer is kept in 16 = bits in=20 your computer, which means that you can only store values between = -32768 and=20 32767 and you want to store 43567 in a variable whose data type is = int. In=20 this case, overflow exists. As a solution you can define your = variable as a=20 long to also keep this value (43567). On the other hand, arithmetic=20 operations that use long variables take longer than those that use = int=20 variables.=20
    • The data type determines its corresponding conversion specifier. = Use=20 %hd, %d, and %ld for short, int, and long values respectively. The = type of=20 variable should match up with the corresponding conversion = specifier,=20 otherwise an undefined behavior occurs.=20
    • Use a or U for unsigned constant values and l or L for long = constant=20 values. For example 30OUl is an unsigned long constant.=20
    • There are also octal (base 8) and hexadecimal (base 16) = representations=20 in C. In the octal representation, digits are between 0 and 7. = 0..9,A..F or=20 0..9,a..f are used as the digits for the hexadecimal representation. =
  2. Floating point numbers=20

    They are real numbers, i.e., the numbers with fractional parts. The = different floating point numbers differ in size and their exact sizes = are=20 changed from one computer to another. But like integers, they have = minimum=20 acceptable sizes according to ANSI standards. Note that there may be = floating=20 point errors (in the significant digits). The different types, their=20 conversion specifiers and constants are given in the Table 1.

    Table 1: The floating point numbers.

      Minimum acceptable size Conversion specifier Example of its constants
    float 1.01037, 6 significant digits %f 3.7, 3.7f, 3.7F, 1.4e2, 1.4E-2
    double 1.01037, 10 significant digits %lf 3.7, 1.4e2, 1.4E-2
    long double 1.01037, 10 significant digits %Lf 3.7, 3.7l, 3.7L, 1.4e2, = 1.4E-2
  3. Characters=20

    A character corresponds to a single byte. char data; is a = declaration=20 statement which defines variable data with a character data type. The=20 conversion specifier of a character is %c.

    A character constant is shown in single quotes, e.g, 'a', '9', 'B', = '+', V,=20 etc. There are also certain characters that can be represented by = using escape=20 sequences: '\n' (newline), '\t' (horizontal tab), '\\' (backslash), = '\"=20 (single quote), '\"' (double quote), etc. Note that they represent = only one=20 character.

    There is a local character set in your machine and character = constant,=20 which is an integer value, is the numeric value of the character in = this local=20 character set. Each character has an unique value, e.g., '0' has the = value of=20 48 in ASCII code. The values range within -128 and 127 and printable=20 characters are always positive. If you define a character variable as = an=20 unsigned char, the values range within 0 and 255.

    We have also the string constant (literal) which consists of zero = or more=20 characters and is surrounded by double quotes, e.g., "It is a string", = "hello=20 world", "" (empty string), etc.

4. variables and constants =

  1. Variable declaration=20

    Variables are data objects which keep values in the memory. A = variable is=20 declared by using the following syntax.

    dataType =
    variableNameList;
    • Each variable must have a data type and have an unique name, = i.e., you=20 can not define different variables with the same name.=20
    • A variable must be declared before it is used.=20
    • Variables can only be declared at the beginning of any block.=20
    • In a single declaration statement, there can be more than one = variable=20 name which are separated by commas. But you can only define the = variables of=20 the same data type in a single declaration statement.=20
    • When you define a variable, its value is garbage (its value can = not be=20 predicted), but there are exceptions. But it is also possible to = initialize=20 the value of a variable when you define it. Note that initializer = must be=20 constant value.=20
    • For printf() and scanf() functions, the type of variable should = match up=20 with the corresponding conversion specifier, otherwise an undefined = behavior=20 occurs.=20
    • x ≠ 'x' ≠ "x"

      x: it is the name of a variable.

      'x': it is a character x.

      "x": it is a string x.

    • 9 ≠ '9' ≠ "9"

      9: it is the integer constant 9.

      '9': it is a character 9, and it has the value of 57 in ASCII = code.

      "9": it is a string 9.


    #include<stdio.h>
    
    int main(){
    	int num1 =3D 0, num2, sum;
    	float Num1;           =20
    	long double tax =3D 4.3;
    	double second;
    	long factorial =3D 40L;
    	char myName =3D 'a', t;
    	char first =3D '\n';
    	double no1 =3D 3.4, no2 =3D 5.6, no3, no4 =3D -132;
    	float last;
    
    	scanf("%d%lf%ld%c",&num1,&second,&factorial,&first);
    	scanf("%f",&Num1);
    	printf("Different numbers: %d\t%ld\t%Lf\n",num2,factorial,tax);
    	printf("More than this, %c %c",myName,first);
    =09
    	anykey();
    	return 0;
    }

  2. Rules for variable names=20

    These rules are also valid for identifier names, e.g., variable = names,=20 function names, symbolic constant names, etc.

    1. They must consist of letters and digits (The underscore = character is=20 counted as a letter). The names of variables do not need to be = meaningful.=20
    2. The names of variables must begin letters. It is also possible = to begin=20 with the underscore character, but it is not recommended since = library=20 routines often use such names.=20
    3. Do not forget that C is a case sensitive, i.e., x and X are = different.=20
    4. At least 31 characters of an internal name are significant (it = depends=20 on a compiler).=20
    5. Keywords like int, main, float, return, long, unsigned, const, = if, etc=20 are reserved and can not be used as identifier names.

    Here are some valid identifier names:

    My_Name8
    number_
    _number
    CMPE
    fdjkfhdg34ffs
    x9875424

    And some invalid identifier names are listed as = follows:

    8Name_4
    4563
    number+
    data\%
    return
  3. Constants=20

    They are values defined as constants, you can not change their = values in=20 the execution of the program. We can define constants by two different = ways.

    1. By using reserved word const. It must be defined in the = declaration part,=20 note that a memory location is allocated for the = constant.

      const type name var name =3D constant =
      value;
      const double PI =3D 3.14;
    2. By using define. Actually it is a substitution and no memory = place is=20 allocated.

      #define PI 3.14

      If you want to define PI as long double use

      #define PI =
      3.14L

      Note that we can use define for other purposes (look at subject=20 macros).

  4. Enumeration constants=20

    It is for defining a list of constant integer values, remember that = character constant values are actually small integer values. It is = alternative=20 to multiple #define's.

    enum Month{JAN =3D 1, FEB, MAR};
    enum BOOLEAN{no, yes};
    enum my_numbers{three =3D 3, one, FOUR =3D 2, five};
    enum specialCharacters{TAB =3D '\t', NEWLINE =3D '\n', BACKSLASH =3D =
    '\\'};
    • They behave like integers.=20
    • Unless it is specified, the values of enumeration constants = begins with=20 0. The other unspecified ones continues from the last specified one. =
    • Names in different enumerations must be distinct.=20
    • Values do not need to be distinct in the same or different = enumeration.=20
    enum boolean{FALSE,TRUE};
    int main (){
    	int a;
    	a =3D FALSE;
    }
    enum boolean{FALSE,TRUE};
    int main (){
    	enum boolean b;
    	b =3D 9;	/* it gives warning */
    	b =3D TRUE;
    }
    int main(){
    	enum boolean{FALSE,TRUE};
    	int a;
    	enum boolean b;
    	a =3D FALSE;
    	b =3D 9;	/* it gives warning */
    	b =3D TRUE;
    }
  5. Assignment and type conversions=20

    When a narrower type is assigned to a wider one, the value is = assigned=20 without losing information. When a wider type is assigned to a = narrower one,=20 we may lose some information.

    int a;
    float b;
    char c;
    a=3D3.14;  /* a =3D 3 */
    b=3D8;     /* b =3D 8.0 */
    c=3D'0';   /* c =3D '0' */
    b=3D9.2;   /* b =3D 9.2 */
    a=3Db;     /* a =3D 9 */
    b=3Da;     /* b =3D 9.0 */
    a=3Dc;     /* a =3D 48, since ASCII code of '0' is 48 */
    b=3Dc;     /* b =3D 48.0 */
    c=3D49;    /* c =3D '1', since ASCII code of '1' is 49 */
    c=3D50.2;  /* c =3D '2' */
    

5. operators

  1. Assignment operator
    x =3D a + y;
    x =3D x + y; or x +=3D y;
    x *=3D y + 1; equals to x =3D x * (y + 1);
  2. Arithmetic operators=20
    • +, =97, *, / → can be applied to all data types (also = character data=20 type).=20
    • % → modulus operator and it can be applied to integers.=20
    • / → integer division (truncates any fraction part) if both = operands are=20 integers.=20
    • When an operator has operands of the different types, the = narrower=20 operator is converted into wider one.
    float x;
    int a, b;
    x=3D5/2;         /* x=3D2.0 */
    x=3D5.0/2;       /* x =3D 2.5 */
    a=3D5.0/2;       /* a =3D 2 */
    a=3D5/2+3/2;     /* a=3D3 */
    b=3D5/2.0+3/2;   /* b=3D3 */
    b=3D5/2.0+3.0/2; /* b=3D4 */
    x=3Da/b;         /* x=3D0.0 */
    b=3Db+a;         /* b=3D7 */
    int c=3D5002;
    char a=3D'0';  /* ASCII code is 48 */
    a=3Da+3;       /* a =3D '3', ASCII code is 51 */
    c+=3Da         /* c =3D 5053 */
    a+=3Dc         /* a =3D ?, overflow and undefined behavior occurs =
    */
    int a;
    char b=3D'A';
    a=3D'9'-'2';   /* a=3D7 */
    a=3D'Z'-b;     /* a=3D26 */
    b=3D'c'+4;     /* b=3D'g' */

    Casting: explicit type conversion can be forced.

    (type name) conversion

    Suppose you have two integers and you want to compute their average = and the=20 ratio of them.

    int x=3D5, y=3D4;
    float avg, ratio;
    avg =3D (x + y)/2;           /* avg =3D 4.0 */
    avg =3D (x + y)/2.0;         /* avg =3D 4.5 */
    avg =3D ((float)x + y)/2;    /* avg =3D 4.5 */
    avg =3D (float)(x + y)/2;    /* avg =3D 4.5 */
    avg =3D (float)((x + y)/2)   /* avg =3D 4.0 */
    
    ratio =3D x/y;               /* ratio =3D 1.0 */
    ratio =3D (float)(x/y);      /* ratio =3D 1.0 */
    ratio =3D (float)x/y;        /* ratio =3D 1.25, the value of x will not =
    change */
    ratio =3D (x+0.0)/y;         /* ratio =3D 1.25 */
  3. Increment and decrement operators=20

    ++ and -- are the increment and the decrement operators = respectively. ++=20 adds 1 to its operand and -- subtracts 1 from its operand. They are = used=20 either prefix or postfix operators.

    n++; (use the value of n first, then increment the value of n by = 1)

    n--; (use the value of n first, then decrement the value of n by = 1)

    ++n; (increment the value of n by 1 first, then use the value of = n)

    --n; (decrement the value of n by 1 first, then use the value of = n)

    int n =3D 5,x;
    n++;     /* n =3D 6 */
    x=3Dn++;   /* n =3D 7, x =3D 6 */
    x=3Dn--;   /* n =3D 6, x =3D 7 */
    int n =3D 5,x;
    ++n;      /* n =3D 6 */
    x=3D++n;    /* n =3D 7, x =3D 7 */
    x=3D--n;    /* n =3D 6, x =3D 6 */
    int a,b,x;
    b=3D3++;      /* invalid */
    ++(x=3D3);    /* x =3D 4 */
    ++x=3D3;      /* x =3D 3 */
    a=3D3;
    ++a+=3D2;     /* a =3D 6 */
    a++ +=3D2;    /* invalid, it gives error */
  4. Relational and logical operators=20
    • For comparing variables and constants we have relational = operators,=20 >, >=3D, <, <=3D, =3D=3D, !=3D. Be careful to use = equality and inequality=20 for floating point numbers.=20
    • Expressions can be connected by logical operators, && = (AND), ||=20 (OR), ! (NOT). If the relation is true, numeric value of the = expression will=20 be 1. If it is false, its numeric value is 0.=20

      Table 2: Truth tables of logical operators

      a b a&&b a||b !a
      0 0 0 0 1
      0 1 0 1 1
      1 0 0 1 0
      1 1 1 1 0
  5. Precedence of operators=20

    The precendence of operators are given in descending order. If you = are not=20 sure on precedence, you can use parentheses.

    Table 4: Precedence of operators.

    () inner first, left to right
    !,++,--,+(unary),-(unary) right to left
    *,/,% left to right
    +,- left to right
    <,<=3D,>,>=3D left to right
    =3D=3D,!=3D left to right
    && left to right
    || left to right
    =3D,+=3D,-=3D,*=3D,/=3D,%=3D assignment statements, right to = left
    a=3D4; b=3D5; c=3D7;
    (a < b 11 b > 7) && c >=3D a;   /*gives 1, which means =
    true*/
    a < b 11 b > 7 && c >=3D a;     /*gives 1, which means =
    true*/
    !(a > b) && c >=3D a;           /*gives 1, which means =
    true*/
    !a > b && c >=3D a;             /*gives 0, which means =
    false*/

6. Input Output operations = just=20 introduction

  1. printf() function
    printf(format in string, var1,var2,...);
    printf("This is \nCmpE150");                 /*it prints the string in =
    double quotes*/
    printf("The number is %d\n",a);              /*it prints the value of a =
    variable*/
    printf("Sum is %f", 3 + 2.0);                /*it prints the results of =
    the operation*/
    • % indicates where other arguments is to be substituted=20
    • Conversion specifiers should match up with the variable type, = otherwise=20 undefined behaviors occur. If you need to use variables with = different data=20 type, you can use casting. Remember the conversion specifiers: short = (%hd),=20 int (%d), long (%ld), char(%c), float (%f), double (%lf), long = double (%Lf)=20

    #include <stdio.h>
    int main(){
       char my_char =3D '0';
       int code;
       code =3D my_char;
       printf("ASCII code of %c is %d",my_char, code);
       anykey();
       return 0;
    }

  2. scanf() function=20

    It reads values into variables from the specified input device. = conversion=20 specifiers should match up with the variable types. In the below = example, it=20 waits for the user to enter values for the variables then press enter = key.=20

    It reads values into variables from the specified input device. = conversion=20 specifiers should match up with the variable types. In the below = example, it=20 waits for the user to enter values for the variables then press enter = key.=20

    scanf("%d%f",&num1,&num2);

    There may be some problems in reading = characters.

    scanf("%c",&b);       /*if you write t and press =
    enter, b =3D 't'*/
    scanf("%c",&b);       /*this time b =3D enter key (b=3D'\n')*/
  3. getchar() function=20

    It reads one character at a time from the standard input device and = returns=20 an integer value. It also waits the user to press the enter key. =

    int ch; char a;
    ch =3D getchar();
    a =3D getchar();
  4. putchar() function=20

    It prints the the value of a character on the standard output. =

    int a; char c;
    putchar(a);
    putchar(c);

    Example: Write a program that takes an uppercase letter from = the=20 user and convert it to its lowercase. you can assume that the user = will enter=20 only uppercase letters.


    #include =
    <stdio.h>
    int main(){
       char a;
       printf("Uppercase letter: ");
       a =3D getchar();
       a +=3D 'a' - 'A';
       printf("Its lowercase: %c\n",a);
       anykey();   =20
       return 0;
    }
    

    Example: Write a program that takes two floating point = numbers and=20 swaps them.


    #include <stdio.h>
    int main(){
       float no1, no2;
       float temp;
       printf("Enter two numbers: ");
       scanf("%f%f",&no1,&no2);
       temp =3D no1;
       no1 =3D no2;
       no2 =3D temp;
       anykey();
       return 0;
    }
    

7. control structures

  1. if statement=20

    So far, a program consists of a number of statements which are = executed in=20 sequence (sequential statements), i.e., they are executed once in all=20 conditions.

    Suppose we want to divide two numbers unless the divisior is equal = to zero.=20 Therefore we need to control the order of statements, i.e., the = program=20 must decide on what to do next

    if (num !=3D 0)
       div =3D first / num;

    Suppose we want to give a message to a student if he passed the = course (if=20 his grade 60).


    #include =
    <stdio.h>
    int main(){
       int grade;
       printf("Enter your grade:\n");
       scanf("%d",&grade);
    
       if (grade >=3D 60)
           printf("You passed");
      =20
       anykey();   =20
       return 0;
    }
    

    Now suppose that, we also want to inform the student if he failed = (if his=20 grade < 60). Then we have optional else where each else must have = if that=20 do not match any else.


    #include =
    <stdio.h>
    int main(){
       int grade;
       printf("Enter your grade:\n");
       scanf("%d",&grade);
    
       if (grade >=3D 60)
           printf("You passed");
       else
           printf("You failed");
      =20
       anykey();   =20
       return 0;
    }
    

    Next we also want to get the number of successful students. = Remember {...}=20 (curly brackets), they represent a block or compound statements and = are used=20 to group more than one statement.


    #include <stdio.h>
    int main(){
       int grade,noSuccessful =3D 0;
       printf("Enter your grade:\n");
       scanf("%d",&grade);
    
      =20
       if (grade >=3D 60){
          printf("You passed");
          noSuccessful++;
       }
       else
          printf("You failed");
    
      =20
       anykey();   =20
       return 0;
    }
    

    The syntax of if statement is as follows:

    if (expression)   =
             =20
       statement block1;
    else               =20
       statement block2;
    • If the expression is true, statement block1 will be executed, = otherwise=20 statement block2 will be executed (if there are no else part than = nothing=20 will be executed).=20
    • The expression should be an integer value, zero means FALSE and = nonzero=20 values mean TRUE.=20
    • else is optional=20
    • A statement block can be a single statement, a compound = statement or a=20 null statement.=20
    • Execution of a program continues normally after if-else. =

    Since expressions are numeric values, we have possible shortcuts. = Consider=20 the exapmle of division by zero.


    #include <stdio.h>
    int main(){
       int x;
       printf("Enter the value of x:");
       scanf("%d",&x);
      =20
       if(x!=3D0){
          printf("x is not zero\n");
       }
      =20
       if(x){
          printf("x is not zero\n");
       }
      =20
       anykey();   =20
       return 0;
    }
    

    Example: Take three integers from the user and display their = average=20 and the smallest and the largest one.


    #include <stdio.h>
    int main(){
       int num1, num2, num3;
       int min, max;
       printf("Enter three integers :");
       scanf("%d%d%d",&num1,&num2,&num3);
       printf("Average of the numbers is %f\n",(num1 + num2 + num3)/3.0);
       if (num1 > num2){
          min =3D num2;
          max =3D num1;
       }
       else{
          min =3D num1;
          max =3D num2;
       }
       if (num3 < min)
          min =3D num3;
       else if (num3 > max)
          max =3D num3;
       printf("Biggest number is %d\n",max);
       printf("Smallest number is %d\n",min);
       anykey();
       return 0;
    }
    

  2. Nested if statements=20

    You can consider if-else structure as a single statement and use it = instead=20 of a stateemnt for other if' s or else' s. We use nested if' s to = encode=20 multiway decisions. Suppose we want to classify the students into = three=20 according to their grades (the ones whose grades are greater than 60, = the ones=20 whose grades in between 50 and 60, and the ones whose grades are = smaller than=20 50) and display a message accordingly.


    #include <stdio.h>
    int main(){
       int grade;
       printf("Enter your grade:\n");
       scanf("%d",&grade);
    
       if (grade >=3D 60)
          printf("You passed");
       else
          if (grade >=3D 50)
             printf("You must take an additional exam");
          else
             printf("You fail");
      =20
       anykey();   =20
       return 0;
    }
    

    Exercise: How do you match else's with if's?

    if (n =
    > 0)                                      if (n > 0){ =20
    
       if (a > b)                                      if (a > b)      =
            =20
    
          n =3D a;                                          n =3D a;         =
          =20
    
       else                                         }                        =
      =20
    
          n =3D b;                                    else                   =
        =20
    
    else                                               n =3D b;              =
        =20
    
       if (a < 0)=20
    
          b =3D 1;
    
       else if (b =3D=3D 0)       =20
    
          b =3D n;    

    Write a program that assigns the letter grade of the score as = follows:=20 90-100 → A, 80-89 → B, 70-79 → C, 60-69 → D, = and 0-59 → F.


    #include =
    <stdio.h>
    int main(){
       int score; char letter;
       printf("Enter your score:");
       scanf("%d",&score);
       if (score > 100 || score < 0)
          printf("Invalid grade...\n");
       else{
          if (score >=3D 90)
             letter =3D 'A';
          else if (score >=3D 80)
             letter =3D 'B';
          else if (score >=3D 70)
             letter =3D 'C';
          else if (score >=3D 60)
             letter =3D 'D';
          else
             letter =3D 'F';
          printf("Your letter grade is %c\n",letter);
       }
       anykey();
       return 0;
    }
    

    Example: Take two decimal numbers and one character from the = user=20 (in the from of no1 character no2) and design a simple calculator. If = the=20 character is +, -, *, or /, your program will be perform the = corresponding=20 operation and display the results, otherwise your program will give a = warning=20 message to the user.


    #include =
    <stdio.h>
    #define SMALL 0.0000001
    int main(){
       float x, y, result;
       char op;
       printf("Your equation: ");
       scanf("%f%c%f",&x,&op,&y);
       if (op =3D=3D '+')
          result =3D x + y;
       else if (op =3D=3D '-')
          result =3D x - y;
       else if (op =3D=3D '*')
          result =3D x * y;
       else if (op =3D=3D '/' && ((y - 0.0 >=3D SMALL) || (y - =
    0.0 <=3D -1 * SMALL)))
          result =3D x / y;
       else{
          printf("invalid operator...\n");
          return 0;
       }
       printf(" =3D %f\n",result);
       anykey();
       return 0;
    }
    

    Example: Write a program that computes and displays the real = roots=20 of the quadratic equation (ax2+bx+c=3D0) whose equations = are taken=20 from the user. The real roots are computes as the following equation: =

    x1,2 =3D = -b=20 =B1 b2-4ac =
    2a

    Let Δ =3D b2-4ac. If Δ<0, there are no real = roots. If Δ=3D0,=20 there is only one real root. If Δ>0, there are two real roots. =


    #include <stdio.h>
    #include <math.h>
    int main(){
       float a, b, c, delta, root1, root2;
       printf("Enter the coefficients of the quadratic equation: ");
       scanf("%f%f%f",&a,&b,&c);
       if (a =3D=3D 0.0)
          printf("The equation is not quadratic\n");
       else{
          delta =3D b * b - 4 * a * c;
          if (delta < 0.0)
             printf("There is no real roots...\n");
          else
             if (delta > 0.0){
                printf("There are two roots...\n");
                root1 =3D (-b + sqrt(delta)) / (2 * a);
                root2 =3D (-b - sqrt(delta)) / (2 * a);
                printf("Roots are %f and %f\n",root1,root2);
             }
             else{
                printf("There is only one root...\n");
                root1 =3D (-b + sqrt(delta)) / (2 * a);
                printf("Root is %f\n",root1);
             }
       }
       anykey();
       return 0;
    }
    

    Example: Write a program that converts the uppercase letter = to its=20 lowercase and converts the lowercase letter to its uppercase = acccording to the=20 case of the letter. You must display a message, if the character is = not a=20 letter.


    #include <stdio.h>
    int main(){
       char C;
       printf("Enter the character : ");
       scanf("%c",&C);
       if (C >=3D 'A' && C <=3D 'Z')
          printf("The lowercase of %c is %c...\n",C,'a'+C-'A');
       else if (C >=3D 'a' && C <=3D 'z')
          printf("The uppercase of %c is %c...\n",C,'A'+C-'a');
       else
          printf("The character is not letter\n");
       anykey();
       return 0;
    }
    

  3. switch statement=20

    Suppose we want to get the number of days in the month whose number = is=20 given.


    #include <stdio.h>
    int main(){
       int mon,days;
       printf("Enter the month: ");
       scanf("%d",&mon);
      =20
       if (mon =3D=3D 4 || mon =3D=3D 6 || mon =3D=3D 9 || mon =3D=3D11)
          days =3D 30;
       else if (mon =3D=3D 2)
          days =3D 28;
       else
          days =3D 31;
      =20
       printf("days:%d\n",days);
       anykey();
       return 0;
    }
    

    Another way to code a multiway decision is using switch = structure.=20


    #include <stdio.h>
    int main(){
       int mon,days;
       printf("Enter the month: ");
       scanf("%d",&mon);
      =20
       switch(mon){
          case 4:
          case 6:
          case 9:
          case 11:
             days =3D 30;
             break;
          case 2:=20
             days =3D 28;
             break;
          default :
             days =3D 31;
             break;
       }
      =20
       printf("days:%d\n",days);
       anykey();
       return 0;
    }
    

    The syntax of switch is as follows:

    switch(expression){
       case constant value1 :=20
          statement(s);
          break;
       case constant value2 :=20
          statement(s);
          break;
        .....
       default:
          statement(s);
          break;
    }
    • The value of the expression is tested and switch branches = depending on=20 this value.=20
    • The type of the value in the expression must be an integral type = (int,=20 short, long, char). If it is not, it gives compile time error.=20
    • Each case must be labeled by an integer constant.=20
    • default is optional and it will be executed if none of = cases are=20 satisfied.=20
    • break statement causes an immediate exit from switch. If = one case=20 is done, execution will fall through next and we must use break to = prevent=20 any further statements from being executed by leaving the switch. It = is also=20 recommended to use break after break.

    #include <stdio.h>
    int main(){
       int num;
       printf("Enter the number: ");
       scanf("%d",&num);
      =20
       switch (num){
          case 1: printf("one "); break;
          case 2: printf("two" );
          case 3: printf("three ");
          case 4: printf("four "); break;
          case 5: printf("five ");
          case 6: printf("six ");
          default: printf("else");
       }
    
       anykey();
       return 0;
    }
    


    #include <stdio.h>
    int main(){
       int num;
       printf("Enter the number: ");
       scanf("%d",&num);
      =20
       switch(num){
          case 1: printf("one "); break;
          default: printf("else");
          case2: printf("two");
       }
    
    
       anykey();
       return 0;
    }
    

    Example: Write a program that computes and displays the area = of the=20 selected geometrical shape which can be square (s,S), rectangle (r,R) = or=20 circle (c,C).


    #include <stdio.h>
    #define PI 3.14
    int main(){
       char choice;
       float a, h, area;
       printf("Enter your choice :");
       scanf("%c",&choice);
       switch (choice){
          case 's': case 'S':
             printf("Enter the edge:");
             scanf("%f",&a);
             area =3D a * a;
             printf("The area of the square is %.4f\n",area);
             break;
          case 'r': case 'R':
             printf("Enter the edge and the height :");
             scanf("%f%f",&a,&h);
             area =3D a * h;
             printf("The area of the rectangle is %.4f\n",area);break;
          case 'c': case 'C':
             printf("Enter the radius :");
             scanf("%f",&a);
             area =3D PI * a * a;
             printf("The area of the circle is %.4f\n",area);
             break;
          default :
             printf("Invalid choice\n");
             break;
       }
       anykey();
       return 0;
    }
    

    Example: Write a program that assigns a letter grade (use = switch).=20


    #include <stdio.h>
    int main(){
       int score;
       char letter;
       printf("Enter your score:");
       scanf("%d",&score);
       if (score > 100 || score < 0)
          printf("Invalid grade...\n");
       else{
          switch(score/10){
             case 10: case 9:
                letter =3D 'A'; break;
             case 8:
                letter =3D 'B'; break;
             case 7:
                letter =3D 'C'; break;
             case 6:
                letter =3D 'D'; break;
             default:
                letter =3D 'F'; break;
          }
          printf("Your letter grade is %c\n",letter);
       }
       anykey();
       return 0;
    }
    

    Example: Write a program that reformats the given date if it = is=20 valid. The day, the month and the year are given as integers and you = must=20 check whether it is a valid date or not.


    #include <stdio.h>
    main(){
       int day, month, year;
       scanf("%d%d%d",&day,&month,&year);
       if (month < 1 || month > 12){
          printf("invalid month...\n");
          return 0;
       }
       if (day < 1){
          printf("invalid day...\n");
          return 0;
       }
       switch(month){
          case 2:
             if ((year%4 !=3D 0 || year%100 =3D=3D 0) && day > =
    28){
                printf("invalid day...\n");
                return 0;
             }
             else
                if (day > 29){
                   printf("invalid day...\n");
                   return 0;
                }
             break;
          case 4: case 6: case 9: case 11:
             if (day > 30){
                printf("invalid day...\n");
                return 0;
             }
             break;
          default:
             if (day > 31){
                printf("invalid day...\n");
                return 0;
             }
             break;
       }
       if (year < 0){
          printf("invalid year...\n");
          return 0;
       }
       printf("%d-",day);
       switch(month){
          case 1: printf("January-"); break;
          case 2: printf("February-"); break;
          case 3: printf("March-"); break;
          case 4: printf("April-"); break;
          case 5: printf("May-"); break;
          case 6: printf("June-"); break;
          case 7: printf("July-"); break;
          case 8: printf("August-"); break;
          case 9: printf("September-"); break;
          case 10: printf("October-"); break;
          case 11: printf("November-"); break;
          case 12: printf("December-"); break;
       }
       printf("%d\n",year);
       anykey();
       return 0;
    }
    

8. repetition statements =

So far, we have seen sequential and control statements. But suppose = the=20 following problems:

  1. Writing a program which prints the line numbers at the beginning = of each=20 line (suppose we have 100 lines).=20
  2. Computing the average of the exam grades of 1000 students.=20
  3. Taking a text from the user and converting its lowercase letters = to their=20 corresponding uppercases until a new line character is pressed.=20
  4. Computing the factorial of the number which is given by the user. =

In cases 1 and 2, it is possible to write the programs by using = sequential=20 statements, however this is not practical. For cases 3 and 4, you cannot = write=20 the necessary codes by only using sequential statements since you do not = know in=20 advance how many times statements are to be executed, e.g., you cannot = know when=20 the user enters a new line character before the execution of the = program. So we=20 need structures to execute the statements repeatedly. A = loop is a=20 group of instructions that the compiler executes repeatedly while some=20 conditions are satisfied.

  1. while=20
    1. Suppose printing 100 lines with their line numbers.
      #include<stdio.h>
      
      int main(){
      	int i =3D 1;                       /* initialization of the control =
      variable i */
      =09
      	while (i <=3D 100){            /* test condition (i <=3D 100) */
      	   printf("line%d\n",i);
      	   i++;                      /* modification of the control variable */
      	}
      =09
      	anykey();
      	return 0;
      }
      
      	

      The statements will be executed repeatedly until the test = condition=20 becomes false (zero). If the test condition is true (nonzero = values), the=20 statement block will be executed. A statement block can be either a = single=20 statement or a compound statement. In the example above, the = statement block=20 are executed until i > 0. In this type of while loop, we know = exactly how=20 many times the statements are to be executed. Suppose the following = code:=20


      #include<stdio.h>
      
      int main(){
      	int i =3D 1;
      	                    =20
      	while (i++ <=3D 100)           /* what happens if we use ++i */
      		printf("line%d\n",i);
      =09
      	anykey();
      	return 0;
      }
      
      	

    2. Compute the average of n numbers entered by the user. You must = take the=20 numbers until a negative value is entered.
      #include<stdio.h>
      
      int main(){
      	float sum =3D 0.0,avg,no;
      	int n =3D 0;
      =09
      	scanf("%f",&no);             /* no controls the execution of while =
      loop*/
      	while (no >=3D 0){             /* (no >=3D 0) is the test =
      condition */
      	   sum +=3D no;
      	   n++;
      	   scanf("%f",&no);          /* modification of the control =
      variable */
      	}
      	if (n > 0){
      	   avg =3D sum / n;
      	}
      	else{
      	   avg =3D 0;
      	}
      	  =20
      	printf("average:%f\n",avg);
      =09
      	anykey();
      	return 0;
      }
      
      	

      In the this example, loop is executed repeatedly until no < 0. = Note=20 that we must initialize some other variables (in this example sum = and n) if=20 necessary. In this type of while loop, we cannot exactly know how = many tims=20 the loop will be executed. The value what we call sentinel indicates = the end=20 of the execution.

      Example: Compute the sum of n numbers entered by the user = where n=20 is also specified by the user at the beginning of the program. =


      #include <stdio.h>
      int main(){
         int i =3D 1, n;
         float number, sum =3D 0.0, avg;
         printf("Enter the number: ");
        =20
         scanf("%d",&n);
         while (i <=3D n){
            printf("Enter the next number: ");
            scanf("%f",&number);
            sum +=3D number;
            i++;
         }
        =20
         if (n > 0){
            avg =3D sum/n;
            printf("The avg is %f\n",avg);
         }
         else{
            printf("n should be greater than 0\n");
         }
        =20
         anykey();
         return 0;
      }
      

      Example: Suppose the effect of the gravity on a free = falling=20 object. Write a program that displays the height of the object = falling from=20 a tower on the screen for every second until it hits the ground. You = must=20 also display a message when the object hits the ground. The height = of the=20 tower h0 is specified by the user and the height h at = time t is=20 h=3Dh0-1/2gt2


      #include <stdio.h>
      #define G  9.81
      
      int main(){
         float tower, height;
         int t;
         printf("Enter the tower height in meters: ");
         scanf("%f",&tower);
         t =3D 0;
         height =3D tower;
         while (height > 0){
            printf("%d\t%f\n",t,height);
            t++;
            height =3D tower - 0.5 * G * t * t;
         }
         printf("OBJECT HITS THE GROUND\n");
         anykey();
         return 0;
      }
      

      Example: Suppose the user enters the sequence of = characters. Write=20 a program that counts the lowercase letters in this sequence until * = is met.=20


      #include <stdio.h>
      
      int main(){
         const char sentinel =3D '*';
         char c;
         int counter =3D 0;
         printf("Enter the sequence of characters: ");
         scanf("%c",&c);
         while (c !=3D '*'){
            if (c >=3D 'a' && c <=3D 'z')
               counter++;
            scanf("%c",&c);
         }
         printf("The number of the lowercase letters is %d\n",counter);
         anykey();
         return 0;
      }
      

  2. for=20

    Consider the following example of printing 100 lines with their = numbers:=20


    #include <stdio.h>
    
    int main(){
       int i;
      =20
       for (i =3D 1; i <=3D 100; i++){
    	   printf("line%d\n",i);
       }
      =20
       anykey();
       return 0;
    }
    

    In this example, variable i controls the loop. It is initialized by = using=20 the initialization statement (i=3D1), which is executed only once, at = the=20 beginning of the loop. Then test condition will be executed, if it = gives true=20 (nonzero) value the statement (or statements) is executed. After = execution of=20 the statement(s), modification part (i++) will be executed and test = condition=20 is checked. The loop continues in the same manner until the test = condition=20 becomes false (zero).

    • For loop consists of three parts: initialization (i=3D1), test = (i<=3D100),=20 and modification (i++). These three parts must be seperated by = semicolon.=20 You can write more than one statements in the initialization and=20 modification part, which are seperated by commas.


      #include <stdio.h>
      
      int main(){
      	int i,j;
      =09
      	for (i =3D 1, j =3D 100; i <=3D 100; i++, j--){
      		printf("i:%d j:%d\n",i,j);
      	}
      =09
      	anykey();
      	return 0;
      }
      

      Note that the statements written in both parts are not resticted = to the=20 arithmetic progression, e.g., you can write =

      scanf(...)
      function, but it is BAD style to force unrelated=20 computations into the initialization and the modification part.=20

    • In the for loop, all expressions are optional, but semicoln must = be used.=20 But the following loop causes an infinite loop which means the loop = is=20 executed forever (avoid infinite loops).


      #include <stdio.h>
      
      int main(){
      	int i;
      =09
      	for ( ; ; ){
      		printf("This will be printed infinitely. Close the window to =
      terminate\n");=20
      	}
      =09
      	anykey();
      	return 0;
      }
      

    • While and for llops can be converted into each other. On the = other hand,=20 for loop is frequently used when we know the number of times of = execution=20 (fixed number of times).

    Example: Suppose we want to compute the factorial of given = number n.=20


    #include <stdio.h>
    int main(){
       int no, i;
       long fact;
      =20
       printf("Enter a number: ");
       scanf("%d",&no);
       fact =3D 1;
      =20
       for (i =3D 2; i <=3D no; i++){
          fact *=3D i;
       }
      =20
       if (no >=3D 0){
          printf("Factorial is %ld\n",fact);
       }
       else{
          printf("It is a negative number");
       }
      =20
       anykey();
       return 0;
    }
    

    Example: Write a program that controls whether the number = entered by=20 the user is perfect or not. Perfect number is the positive number = whose sum of=20 its positive divisors except itself is equal to itself. For example 6 = and 28=20 are perfect numbers (6 =3D 1 + 2 + 3)


    #include <stdio.h>
    
    int main(){
       int number, i, sum =3D 0;
       scanf("%d",&number);
       for (i =3D 1; i <=3D number / 2 ; i++)
          if (number % i =3D=3D 0)
             sum +=3D i;
       if (number =3D=3D sum)
          printf("%d is a perfect number",number);
       else
          printf("%d is not a perfect number",number);
       anykey();
       return 0;
    }

  3. do-while=20

    While and for loops test the termination condition at the top, = whereas=20 do-while tests it at the bootm after a pass through the loop body. The = body of=20 the do-while loop is always executed at least once.

    Consider displaying 100 lines with their numbers:


    #include <stdio.h>
    
    int main(){=09
    	int i =3D 1;
    =09
    	do{
    		printf("line%d\n",i);
    		i++;
    	}while( i <=3D 100);
    =09
    	anykey();
    	return 0;
    }

    In this example, statements in the loop body are executed first, = then if=20 the expression true the statements will be reexecuted again. The loop=20 continues until the test condition becomes false. Note that use this = loop, if=20 you know that the loop body is going to be executed at least once.

    Example: Write a program that computes the area of the = square. At=20 the end of each computation, your program should ask the user whether = he wants=20 to continue or not, and exits if the user presses q/Q key. Otherwise = it=20 continues to process.


    #include =
    <stdio.h>
    int main(){
       char choice;
       float a;
       do{
          printf("Enter the edge ");
          scanf("%f",&a);
          printf("area =3D %f\n",a * a);
          printf("Press q/Q to quit...\n");
          printf("Or any other key to continue...\n");
          scanf("\n%c",&choice);
       }while(choice !=3D 'q' && choice !=3D 'Q');
      =20
       anykey();
       return 0;
    }
    

    Example: Write a program that computes the perimeter of a = polygon=20 whose size is specified by the user. If the size can not form a = polygon should=20 display a warning message. Otherwise you ask each side to the user and = compute=20 the perimeter.


    #include <stdio.h>
    
    int main(){
       int size =3D 0;
       float len, p =3D 0;
       printf("Enter the size :");
       scanf("%d",&size);
       if (size < 3)
          printf("no polygon...\n");
       else{
          do{
             printf("Enter the edge : ");
             scanf("%f",&len);
             p +=3D len;
             size--;
          }while(size > 0);
          printf("Perimeter =3D %f\n",p);
       }
       anykey();
       return 0;
    }
    

  4. Nested loops=20

    We can have two or more loops inside each other (like nested if' s = or=20 switch' s).

    Example: Draw the isosceles triangle using *, where line = number is=20 also specified by the user.


    #include =
    <stdio.h>
    
    int main(){
    	int line, i, j;
    	printf("Enter the height :");
    	scanf("%d",&line);
    =09
    	for (i =3D 1; i <=3D line; i++){
    		for (j =3D 0; j < line - i; j++){
    			printf(" ");
    		}
    		for (j =3D 0; j < i * 2 - 1; j++){
    			printf("*");
    		}
    		printf("\n");
    	}
    =09
    	anykey();
    	return 0;
    }
    

    Example: Write a program which reads the input as a sequence = of=20 characters terminated by '! '. Your program should detect the longest = sequence=20 of the lowercase letter repeated. Display which letter it is and the = number of=20 its occurrences.


    #include =
    <stdio.h>
    
    int main(){
       int n;
       float sum;
       char current, prev, longest;
       int max =3D 0, current_no =3D 0;
      =20
       printf("Enter the sequence ended with !  ");
       scanf("%c",&current);
       prev =3D current;
       while (prev !=3D '!'){
          if (prev =3D=3D current )
             current_no++;
          else{
             if (current_no > max && prev >=3D 'a' && =
    prev <=3D 'z'){
                longest =3D prev;
                max =3D current_no;
             }
             current_no =3D 1;
          }
          prev =3D current;
          scanf("%c",&current);
       }
       if (max > 0)
          printf("%c occurs %d times\n",longest,max);
       else
          printf("no lowercase letters\n");
       anykey();
       return 0;
    }
    

    Example: Write a program which reads real numbers from the = user=20 until the last read number is twice the number read before it. The = program=20 will calculate the average of the given numbers.


    #include <stdio.h>
    int main(){
       int no1, prev, count =3D 1;
       float avg,sum;
       printf("Enter a number:");
       scanf("%d",&no1);
       avg =3D prev =3D no1;
       while (no1 !=3D 2 * prev){
          prev =3D no1;
          printf("Enter a number:");
          scanf("%d",&no1);
          sum +=3D no1;
          count++;
       }
       avg =3D sum/count;
       anykey();
       return 0;
    }
    

  5. break=20

    It provides an early exit from em for, while, do-while just as = switch. It=20 causes the innermost enclosing loop or switch to be exited = immediately.

    Suppose taking the average of numbers entered by the user. You must = stop=20 when a negative value is entered.


    #include <stdio.h>
    
    int main(){
    	int number,n;
    	float avg;
    	avg =3D n =3D 0;
    	while (1){
    		scanf("%d",&number);
    		if (number < 0)
    			break;
    		avg +=3D number;
    		n++;
    	}
    	if (n > 0)
    		avg /=3D (float)n;
    	printf("average:%f",avg);
    	anykey();
    	return 0;
    }
    

    Example: You want to take a single integer from the user. = But you=20 want to control whether the entered number is valid or not, the = numbers=20 includes characters other than digits are invalid. And you know that = if a=20 white blank character, i.e, enter, tab or space, is hit, you = understand that=20 the integer ends.


    #include =
    <stdio.h>
    int main(){
       char c;
       long number =3D 0;
       int invalid =3D 1;
    
       c =3D getchar();
       while (c !=3D ' ' && c !=3D '\n' && c !=3D '\t'){
          invalid =3D 0;
          if (c > '9' || c < '0'){
             invalid =3D 1;
             break;
          }
          number =3D number * 10 + c - '0';
          c =3D getchar();
       }
       if (invalid)
          printf("The input is an invalid integer\n");
       else
          printf("You entered %ld\n",number);
       anykey();
       return 0;
    }
    

  6. continue=20

    It causes the next iteration of the enclosing for, while, do-while = to=20 begin. It cannot be used with switch' s. For while and do-while loops, = the=20 test part is executed immediately. In for loops, the control passes to = the=20 modification step.

    Suppose you have the following loops, and the input of the program = is: 5 -4=20 3 2 -5 8 9 1.


    #include <stdio.h>
    
    int main(){
    	int i =3D 0, sum =3D 0,no;
    								 =20
    	while (i < 6){
    		scanf("%d",&no);
    		if (no <=3D 0)
    			continue;
    		sum +=3D no;
    		i++;
    	}
    	/* sum becomes 28 */
    	printf("sum:%d\n",sum);
    =09
    	anykey();
    	return 0;
    }


    #include <stdio.h>
    
    int main(){
    	int i =3D 0, sum =3D 0,no;
    =09
    	for (i =3D 0; i < 6; i++){
    		scanf("%d",&no);
    		if (no <=3D 0)
    			continue;
    		sum +=3D no;		 =20
    	}=09
    	/* sum becomes 18 */
    	printf("sum:%d\n",sum);
    =09
    	anykey();
    	return 0;
    }
    

9. functions

Why are functions necessary?

  1. Real-world problems are much larger than the ones we examined so = far. Thus=20 we need to break up the problem into the smaller subproblems. Given a = problem,=20 we start its abstract formulation first and work down to more detailed = subproblems.=20
  2. Functions enables us to reuse the codes written before. For = example there=20 are standard functions defined in stdio.h, and we use them for our = purposes.=20 Or consider computing the permutation of two numbers, = P(n,k)=3Dn!/(n-k)!. In=20 this example we must compute the factorial twice, i.e., we must write = its code=20 twice. Instead of that, just define a function for this purpose and = use if it=20 is necessary (like printf(), scanf(), etc. functions). So we have = compact=20 codes.

Consider drawing a square by using - and |'s for different cases.

  1. We want to write a program which draws 2x2 square.
    #include <stdio.h>
    
    int main(){
       printf(" -- \n");
       printf("|  |\n");
       printf("|  |\n");
       printf(" -- \n");
       anykey();
       return 0;
    }

  2. In above program, if we want to draw 2 2 square at different = places in our=20 program, we should write the same code many times. So write this code = only=20 once in a function, then just call it by using its name.
    #include <stdio.h>
    
    void drawSquare(){
       printf(" -- \n")
       printf("|  |\n");
       printf("|  |\n");
       printf(" -- \n")
    }
    int main(){
       drawSquare();
       anykey();
       return 0;
    }
    

  3. But in the above code, this function works just for 2x2 squares. = Let us=20 generalize it such that it works for nxn squares. Send n as a = parameter to the=20 function.
    #include <stdio.h>
    
    void drawSquare(int n){
       int i, j;
       printf(" ");
       for (i =3D 0; i < n; i++)
          printf("-");
       printf("\n");
       for (i =3D 0; i < n; i++){
          printf("|");
          for (j =3D 0; j < n; j++)
             printf(" ");
          printf("|\n");
       }
       printf(" ");
       for (i =3D 0; i < n; i++)
          printf("-");
       printf("\n");
    }
    
    int main(){
       int n =3D 3;
       drawSquare(n);
       n =3D 5;
       drawSquare(n);
       anykey();
       return 0;
    }
    

  4. In the above function you wrote the code for printing a single = horizontal=20 line twice. So we can define another function for this purpose. This = new=20 function must also know the size of the square, so pass this value to = the new=20 function as a parameter.
    #include =
    <stdio.h>
    
    void drawHorizontal(int n){
       int i;
       printf(" ");
       for (i =3D 0; i < n; i++)
          printf("-");
       printf("\n");
    }
    
    void drawSquare(int n){
       int i, j;
       drawHorizontal(n);
       for (i =3D 0; i < n; i++){
          printf("|");
          for (j =3D 0; j < n; j++)
             printf(" ");
          printf("|\n");
       }
       drawHorizontal(n);
    }
    
    int main(){
       int n =3D 3;
       drawSquare(n);  =20
       n =3D 5;
       drawSquare(n);
       anykey();
       return 0;
    }
    

  5. Again you can define another function that performs displaying a = vertical=20 line as in follows:
    #include =
    <stdio.h>
    
    void drawHorizontal(int n){
       int i;
       printf(" ");
       for (i =3D 0; i < n; i++)
          printf("-");
       printf("\n");
    }
    
    void drawVertical(int n){
          int i;
          printf("|");
          for (i =3D 0; i < n; i++)
             printf(" ");
          printf("|\n");
    }
    
    void drawSquare(int n){
       int i, j;
       drawHorizontal(n);
       for (i =3D 0; i < n; i++)
          drawVertical(n);
       drawHorizontal(n);
    }
    
    int main(){
       int n =3D 3;
       drawSquare(n);
       n =3D 5;
       drawSquare(n);
       anykey();
       return 0;
    }
    

  6. If you want to generalize your function such that it draws nxm = rectangle,=20 you must send these two information to the function such as:
    #include <stdio.h>
    
    void drawHorizontal(int n){
       int i;
       printf(" ");
       for (i =3D 0; i < n; i++)
          printf("-");
       printf("\n");
    }
    
    void drawVertical(int n){
          int i;
          printf("|");
          for (i =3D 0; i < n; i++)
             printf(" ");
          printf("|\n");
    }
    
    void drawRectangle(int n, int m){
       int i, j;
       drawHorizontal(m);
       for (i =3D 0; i < n; i++)
          drawVertical(m);
       drawHorizontal(m);
    }
    
    /*check how drawSquare function can be written using drawRectangle =
    function*/
    void drawSquare(int n){
    	drawRectangle(n,n);
    }
    
    int main(){
       int n =3D 3, m =3D 4;
       drawRectangle(n,m);
       n =3D 5;
       drawRectangle(n,n+m);
       drawSquare(3);
       anykey();
       return 0;
    }
    

  • The syntax for defining a function is as follows: =
    return_value_data_type   function_name(parameter_list){
       declarations
       statements
    }
  • The function name is any valid identifier name, and the function = is called=20 with its name.=20
  • {...} indicates the function body, which may consist of = declarations and=20 statements.=20
  • The parameter list provides the caller to send data to the = function. In C,=20 only values can be passed to the functions, not the variables. The = values of=20 parameters in the caller part can be a vaiable, a constant or an = expression as=20 in the following example.
    void my_function(int n, float k, char =
    c){
       ...
    }=20
    main(){
       int b =3D 3; float a; char d;
       my_function(b,5.6,d + 2- '+');
    }
    Parameter list can consists of more thamn one variables, which = are=20 seperated by commas and for each the data type must be specified in = the=20 function part (not when you call it, in the caller part). If there is = no=20 parameter, no communication between the caller and the function.=20
  • Function should return a value unless it is not specified, we use = void to=20 indicate that our function won't return any value. This is the only = way to=20 send data from function to the point where it was invoked (called), = and only a=20 single value can be returned. You must specify the data type of the = returned=20 value at the beginning of the function. If you omit, it returns an = integer=20 (think of main function). Consider the following example:
    float =
    F1(int n, char c){
       ....
       return  (n / 0.2);
    }
    In this case caller send the function two values (n and c) and = function=20 will send a single float value (n/2) to its caller. A function will be = terminated either it returns or with right brace(}). A function can = return a=20 value at any place in the function body.=20
  • Functions must be declared before they are used. Thus you must = declare the=20 functions before their callers or you must define their prototypes = before=20 their callers. By defining a prototype, you should just write its = return type,=20 its name and its parameter list as in the following example:
    void =
    draw_vertical(int size);
    void draw_vertical(int);
    long factorial(int); 
    Note that we cannot define a function in = another.=20
  1. Scopes=20

    A variable has a scope such that this variable is only defined in = this=20 scope. There are three different scopes:

    1. Block Scope: Any block contain variable declarations, = which must=20 be defined at the beginning of a block. You can use these variables = only in=20 the block, where they are defined. Some examples:=20
    2. Function Scope: The variables defined at the beginning of = a=20 function has function scope. These variables are called local = variables.=20 They can be used anywhere in the function where they appear, and = cnnot be=20 used outside the function body.=20
    3. File Scope: The variables declared outside any function = has file=20 scope. They can be used in all functions from the point at which the = variable is declared until the end of file. These are called global=20 variables. But unless it is necessary, avoid using global variables = in your=20 program.
      double G;             /* G is the global variable */
      int function1(){
         int a;             /* a is the local variable */
         if (a < 0){
            float b;        /* b has block scope, and can be used only in this =
      if */
         }
         for (a =3D 1; a < 100; a++){
            char c;        /* c has block scope, and can be used only in this =
      for */
         }
      }

    If a variable is used in a code, it is searched as the following = order: 1)=20 In its block, 2) Among the local variables, 3) Among the global = variables.=20 Note that variables with block or function scope have garbage value = when they=20 are declared, unless they are initialized. On the other hand, global = variables=20 are initialized with zero in the absence of initializations.

    Example: What is the output of the program?


    #include <stdio.h>
    
    int a =3D 5, b =3D 3;
    float c =3D 10;
    
    first(float a, float b, int ch){
       printf("first #1 a =3D %f, b =3D %f, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,ch);
       a =3D b + ch;
       c--;
       return (a + b--);
    }
    float second(int a, float c){
       int ch =3D 2;
       printf("second #1 a =3D %f, b =3D %d, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,ch);
       b =3D first(b,c,ch);
       printf("second #2 a =3D %f, b =3D %d, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,ch);
       return (b * c);
    }
    main(){
       float b =3D 5.99, ch =3D 1.2;
       printf("main #1 a =3D %f, b =3D %f, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,(int)ch);
       a =3D first(ch,c,b);
       printf("main #2 a =3D %f, b =3D %f, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,(int)ch);
       ch =3D second(c,b);
       printf("main #3 a =3D %f, b =3D %f, c =3D %f, ch =3D =
    %d\n",(float)a,b,c,(int)ch);
       return 0;
    }
    
    /*
    Output is:
    main   #1 a =3D 5.00,  b =3D 5.99,  c =3D 10.00, ch =3D 1
    first  #1 a =3D 1.20,  b =3D 10.00, c =3D 10.00, ch =3D 5
    main   #2 a =3D 25.00, b =3D 5.99,  c =3D 9.00,  ch =3D 1
    second #1 a =3D 9.00,  b =3D 3,     c =3D 5.99,  ch =3D 2
    first  #1 a =3D 3.00,  b =3D 5.99,  c =3D 9.00,  ch =3D 2
    second #2 a =3D 9.00,  b =3D 13,    c =3D 5.99,  ch =3D 2
    main   #3 a =3D 25.00, b =3D 5.99,  c =3D 8.00,  ch =3D 77
    */
    
    

    Example: Write a function that computes nk. Assume k is an = integer.=20


    #include<stdio.h>
    
    double pow(double number, int power){
       int i; double temp =3D 1.0;
       if (power =3D=3D 0)
          return 1.0;
       for (i =3D 0; i < power; i++)
          temp *=3D number;
       if (power < 0)
          temp =3D 1.0 / temp;
       return temp;
    }
    
    
    int main(){
    	double number,result;
    	int power;
    =09
    	printf("Enter a number and its integer power:\n");
    	scanf("%lf%d",&number,&power);
    =09
    	result =3D pow(number,power);=09
    	printf("%lf^%d is %lf\n",number,power,result);
    =09
    	anykey();
    	return 0;
    }

    Example: Write functions that compute the permutation,=20 P(n,k)=3Dn!/(n-k)!, and the combinatorial, C(n,k)=3Dn!/(n-k)! k!, of = two numbers n=20 and k, where n>0, k>0, and n k.


    #include<stdio.h>
    
    double pow(double number, int power){
       int i; double temp =3D 1.0;
       if (power =3D=3D 0)
          return 1.0;
       for (i =3D 0; i < power; i++)
          temp *=3D number;
       if (power < 0)
          temp =3D 1.0 / temp;
       return temp;
    }
    
    
    int main(){
    	double number,result;
    	int power;
    =09
    	printf("Enter a number and its integer power:\n");
    	scanf("%lf%d",&number,&power);
    =09
    	result =3D pow(number,power);=09
    	printf("%lf^%d is %lf\n",number,power,result);
    =09
    	anykey();
    	return 0;
    }

    Example: Write functions that compute the permutation,=20 P(n,k)=3Dn!/(n-k)!, and the combinatorial, C(n,k)=3Dn!/(n-k)! k!, of = two numbers n=20 and k, where n>0, k>0, and n k.


    #include<stdio.h>
    
    long factorial(int n){
       int i; long res =3D 1;
       if (n =3D=3D 0)
          return 0;
       for (i =3D 1; i <=3D n; i++)
          res *=3D i;
       return res;
    }
    long perm(int n, int k){
       long result;
       if (n < 0 || k < 0 || n < k)
          return 0;
       else{
          result =3D factorial(n) / factorial(n - k);
          return result;
       }
    }
    long comb(int n, int k){
       long result;
       if (n < 0 || k < 0 || n < k)
          return 0;
       else
          return (factorial(n) / (factorial(n - k) * factorial(k)));
    }
    
    int main(){
    	int n=3D5,k=3D3;
    	printf("factorial:%ld permutation:%ld =
    combination:%ld\n",factorial(n),perm(n,k),comb(n,k));
    	anykey();
    	return 0;
    }
    

10. macro substitution =

Remember
#define PI 3.14 
in the compile time all PI' s = are substituted with=20 3.14. We can use it to replace a token by an arbitrary sequence of = characters.=20 We call them macro and the general format is as follows:
#define =
name replacement_text 
where name has the form of the=20 identifier name. It is also possible to define macros with arguments. To = compute=20 the square of a given number, you can define a macro:
#define =
square(x) (x)*(x) 
In this example parentheses are important=20 to prevent the misinterpretations. In your program you use this macro = as:
a =3D square(3);
b =3D square(a + 3 * b);
Or you can define a maximum operation, = which finds=20 the maximum of given two numbers as:
#define max(A,B) (((A) > =
(B)) ? (A) : (B)) 
In your program, it can=20 be used as z=3Dmax(p+q,r+s); Do not forget that it is just a text = substitution,=20 which is performed at the compile time.=20

11. pointers and pointer = arithmetic=20

A pointer is a variable that is capable to hold a memory address in = it.=20 Suppose the declaration of the integer pointer p:
int *p; =
p keeps an address in it, and in this address an=20 integer is held since it is an integer pointer, in case of float pointer = A,
float *A;
, A keeps an address in it and in this address a = floating=20 number is held. Note that you can also keep an integer value in the = address,=20 which pointer A keeps, but it may cause some problems. Also note that a = pointer=20 is a variable too, thus it is kept in some memory place, i.e., it has = some=20 memory address, which is not the same with its value. Every pointer = points to a=20 specific data type except void pointers. Pointer to void is used to hold = any=20 type of pointer.=20
  1. Pointer operators=20
    1. & (address operator): It is a unary operator, and it = gives=20 the address of its operand. It can be applied to objects in memory, = it=20 cannot be applied to expressions, constants or register variables. = Suppose=20 the following statements:
      int *p, c
      p =3D &c; 
      In the first line we declare two variables, one is = an=20 integer, the other is an integer pointer. In the second line, we = assign the=20 address of c as the value of variable p.=20
    2. * (indirection(dereferencing) operator): It is also a = unary=20 operator and can be applied to pointers. By this operator, we can = access the=20 variable whose address is kept in the pointer. You should only = access to=20 addresses which was previously allocated, otherwise you may have = some=20 problem. For example:
      int *p;
      *p =3D 3; 
      You define an integer pointer p, which has garbage value = in=20 it, so in its address there can be any address. And when you try to = access=20 to the address, which is the value of p, you may probably access an=20 unallocated address.

    Example:


    #include<stdio.h>
    
    int main(){
       int a =3D 3, b =3D 2, *ptr, *x, *y;
       ptr =3D &a;         /* ptr has the value of the address of a      =
                */
       printf("ptr:%d\n",ptr);
       b =3D *ptr;         /* in the p, address of a is kept, then by using =
    *ptr,  =20
                                           you access to variable a, then b =
    =3D 3    */
       printf("b:%d *ptr:%d ptr:%d\n",b,*ptr,ptr);
       *ptr =3D a;         /* value of a does not change */
       printf("a:%d\n",a);
       x =3D ptr;          /* the value of ptr assign to the varable x       =
            */
       printf("x:%d\n",x);
       x =3D &*ptr;        /* first access the variable which is stored =
    in the      =20
                            address, whose value is kept in ptr, then take =
    its    =20
                            address, the result is simply equal to the value =
    of ptr*/
       printf("x:%d\n",x);
       y =3D *&ptr;        /* take the address of the variable ptr, then =
    access the =20
                            the variable that is stored in this address. =
    This is  =20
                            simply the value stored in ptr                   =
          */
       printf("y:%d\n",y);
       a =3D *&b;          /* take the address of variable b, then =
    access the variable
                            which is stored in this address, simply b        =
          */
       printf("a:%d b:%d\n",a,b);
       a =3D &*b;          /* invalid, since * can be applied to =
    pointers or addresses. comment out this line for successful compile*/
       				=09
       anykey();
       return 0;
    }
    

    We can also use addition and subtraction operator with pointers. =


    #include<stdio.h>
    
    int main(){
       int a =3D 3, *x, *y;
       y =3D &a;           /* we assign the address of a to the variable =
    x           */
       printf("y:%d\n",y);
       x =3D y;            /* copy y to x, then x keeps the address of a too =
            */
       printf("x:%d\n",x);
       *y +=3D 1;          /* first access the variable that is stored in =
    the address
                            kept by y, then increment it by one, thus a =3D =
    4        */
       printf("a:%d *y:%d y:%d\n",a,*y,y);
       y =3D y + 1;        /* increment the value of pointer y, now y has =
    the value of
                            address next to the variable a (according to =
    integers) */
       printf("y:%d\n",y);
       y--;              /* decrement the value of pointer y by one, y now =
    keeps=20
                            the address of variable a                        =
          */
       printf("y:%d\n",y);
       anykey();
       return 0;
    }
    

12. pointers and function = arguments=20

Suppose we have a function, and we want to change two values in it = and return=20 them to the caller part. But only a single value can be returned and = there is no=20 direct way to alter a parameter in C programming language. The way to = obtain=20 this effect is to pass pointers to the functions. Suppose the example of = swaping=20 two values which are sent as the parameters.


#include<stdio.h>

void swap(int a, int b){
   int temp =3D a;
   a =3D b;
   b =3D temp;
}

int main(){
   int m =3D 3, n =3D 4;
   swap(m,n);
   printf("m:%d n:%d\n",m,n);
   anykey();
   return 0;
}

After calling swap function in the main, there is no effect of this = function.=20 The values of the variables a and b are changed in the function but the = values=20 of m and n remain same, since there are no connections between variables = m and=20 a, and n and b.


#include<stdio.h>

void swap(int *a, int *b){
   int temp =3D *a;
   *a =3D *b;
   *b =3D temp;
}

int main(){
   int m =3D 3, n =3D 4;
   swap(&m,&n);
   printf("m:%d n:%d\n",m,n);
   anykey();
   return 0;
}

In this case, we send the addresses of m and n and we change the = values of=20 variables stored in these addresses in the swap function. We know that = we can=20 access the variables stored in any address by using the dereferencing = operator=20 *. So we access the variables of m and n, which are the local variables = of main,=20 indirectly in the swap function. So after calling swap in the main, the = value of=20 m becomes 4 and the value of n becomes 3, i.e., we swap their = values.

Example: Consider the program, which finds the real roots of a = given=20 quadratic equation. At this time, we want to rewrite it by using a = function.=20


#include <stdio.h>
#include <math.h>
#define small 0.000001
#define equal(a,b) ((a) - (b) <=3D small) && ((b) - (a) =
<=3D small)
float delta(float a, float b, float c){
   return (b * b - 4 * a * c);
}
int solve(float a, float b, float c, float *root1, float *root2){
   float d;
   if (equal(a,0.0))
      return -1;
   d =3D delta(a,b,c);
   if (equal(d,0.0)){
      *root1 =3D (-1 * b) / (2 * a);
      return 1;
   }
   if (d < 0)
      return 0;
   *root1 =3D (-1 * b + sqrt(d)) / (2 * a);
   *root2 =3D (-1 * b - sqrt(d)) / (2 * a);
   return 2;
}
int main(){
   float r1, r2;
   float a, b, c;
   printf("Enter equation coefficients: ");
   scanf("%f%f%f",&a,&b,&c);
   switch (solve(a,b,c,&r1,&r2)){
      case -1 : printf("Not quadratic equation\n");
         break;
      case 0 : printf("No real roots\n");
         break;
      case 1 : printf("One real root\n");
         printf("Root1 =3D Root2 =3D %f\n",r1);
         break;
      case 2 : printf("Two real roots\n");
         printf("Root1 =3D %f\n",r1);
         printf("Root2 =3D %f\n",r2);
         break;
   }
   anykey();
   return 0;
}

13. arrays

Suppose we want to take N integers, xi, from the user and =

  1. We want to compute the average of these numbres, where=20
    avg=3D
     
    N
    Σ xi
    i=3D1 =
    N

    #include<stdio.h>
    #define N 5
    
    int main(){
    	float avg =3D 0;
    	int no;
    	for (i =3D 0; i < N; i++){
    	   scanf("%d",&no);
    	   avg +=3D no;
    	}
    	avg /=3D N;
    	printf("average:%f\n",avg);
    	anykey();
    	return 0;
    }

  2. We want to compute the variance of the numbers xi, = where=20 variance is=20
    var=3D
     
    N
    Σ = (xi-avg2)
    i=3D1=20
    N

    For this time, we need to keep xi values since first we = need to=20 compute the average value, then use this value in the variance = computation.=20 One way is to keep each number in distinc variables. For example if = N=3D100,=20 then we need to declare 100 variables. But it is not feasible. The = next=20 alternative way is to group these variables under the same name, where = each of=20 them has an unique index.

    An array is a group of memory locations. These locations are = related=20 by the fact that they have all the same name and same type. To refer = (access)=20 to a particular location, i.e., an element within the array, specify = the name=20 of the array and the position number (index) of the variable in square = brackets.


    #include<stdio.h>
    
    int main(){
    	int X[100];
    	float avg =3D 0,var=3D0;
    	for (i =3D 0; i < 100; i++){
    		scanf("%d",&no);
    		avg +=3D no;
    		X[i] =3D no;
    	}
    	avg /=3D 100;
    	for (i =3D 0; i < 100; i++)
    		var +=3D (X[i] - avg) * (X[i] - avg);
    	}
    	var /=3D 99;
    =09
    	printf("average:%f variance:%f\n\n",avg,var);
    	anykey();
    	return 0;
    }

    We must declare arrays before using them.

    int X[100];
    float Y[90], Array[10]; 
    • float Y[90]; tells the compiler to reserve 90 elements for float = array=20 Y, i.e., to allocate 90 memory locations, each of which are capable = to store=20 a float value.=20
    • Arrays (their elements) occupy space in the memory, so you must = specify=20 the number of allocations, e.g., 90 for the array Y. You need = constant=20 expressions for these numbers. For example, the following definition = is=20 valid:
      #define b 3
      const int mySize =3D 2;
      int y[a*b+2];
    • We can use its elements like variables, such as:
      float =
      A[10];
      A[3] =3D 2;               /* assign 2 to the third element of the array =
      A      */
      A[4] =3D A[3] * 2;        /* get the value of the third element of the =
      array A,=20
                                 multiply it by 2, then assign the result into =
      the=20
                                 fourth element of the array A                 =
          */
      A[3]++;                 /* increment the value of the third element by 1 =
          */
    • The index of the first element of the array is zero, i.e., = arrays begin=20 with 0th element. And the index of the last element is = N-1, where=20 N is the size of the array.=20
    • Indices can only be either an integer or an integer expression. =
      int k[5], i;
      for (i =3D 0; i < 5; i++)
         k[i] =3D i * 2;
      k[2*2 - 1] =3D 3;
      k[k[4] / k[1]] =3D 2;
      k[1.5] =3D 3;           /* error occurs */
    • Elements of the array can be considered as variables, however = array name=20 is not a variable. Suppose we define double NewArray[5];, we have = variables=20 NewArray[0], NewArray[1], etc. But there is no variable with the = name of=20 NewArray.=20
    • Do not try to access the elements extending the size of an = array.=20 Suppose you define an array as int k[5];, then you should not try to = access=20 k[-45], k[-1], k[5], k[22], etc. Note that that is permitted, but = you may=20 have some problems if these are not allocated memory cells. =

    It is also possible to initialize arrays at the declarations, give = the=20 values of elements in a comma separated list.

    int n[4] =3D =
    {1,2,3,4};
    int n[4] =3D {1,2,3,4,5};         /* too much values (grater than the =
    size of=20
                                       the array), it gives compile time =
    error   */
    int n[4] =3D {2,3};               /* fewer initializers, remaining =
    elements are=20
                                       initialized by zero                   =
        */
    int n[] =3D {1,2,5,3,7,7,0};      /* it works, the compiler will create =
    an array
                                       whose size equals to the number of =
    the=20
                                       initializers, in this case with size =
    7    */
    int n[];                        /* it gives compile time error*/

    Arrays are static structures, which means you set the size of the = array in=20 your code and cannot change its size anymore. In summary you should = either=20 specify the array size or initialize the array.

    Example: Suppose you have 100 elements with integer data = type. You=20 want to control whether these numbers are symmetric or not. Consider = elements=20 are given in a sequence by the user.


    #include <stdio.h>
    
    int main(){
       int numbers[100], i;
       for (i =3D 0; i < 100; i++)
          scanf("%d",&numbers[i]);
       for (i =3D 0; i < 50; i++)
          if (numbers[i] !=3D numbers[99 - i])
             break;
       if (i =3D=3D 50)
          printf("they are symmetric\n");
       else
          printf("they are not symmetric\n");
       anykey();
       return 0;
    }                =20
    

    Example: User enters a sequence of characters. You want to = count the=20 lowercase and the uppercase letters in this sequence. The sequence is = finished=20 when % is entered. You should ignore all other characters. =


    #include <stdio.h>
    
    int main(){
       int upper[26] =3D {0}, lower[26], i;
       char a;
       for (i =3D0; i < 26; i++)
          lower[i] =3D 0;
       printf("enter characters: ");
       scanf("%c",&a);
       while (a !=3D '%'){
          if ((a <=3D 'z') && (a >=3D 'a'))
             lower[a - 'a']++;
          else if ((a <=3D 'Z') && (a >=3D 'A'))
             upper[a - 'A'] +=3D 1;
          scanf("%c",&a);
       }
       anykey();
       return 0;
    }
    

    Arrays have one important drawback: They cannot be created = or used=20 dynamically. For example, consider the user enters a sequence of = decimal=20 numbers but we do not know the size of this sequence at the beginning = of the=20 program (suppose size is also given by the user or the numbers are = taken until=20 the user enters a sentinel value). We can solve this problem by = defining very=20 large arrays and hope the user not to enter the size such that it = extends the=20 limit. Suppose the following examples:


    #include<stdio.h>
    
    int main(){
    =09
    	float userNos[100000], sum;
    	int i, n;
    	scanf("%d",&n);
    	for (i =3D 0; i < n; i++)
    	   scanf("%f",&userNos[i]);
    	sum =3D 0;
    	for (i =3D 0; i < n; i++)
    	   sum +=3D userNos[i];
    	printf("sum is %f\n",sum);
    	anykey();
    	return 0;
    }

    If user enters the size smaller than or equal to 100000, the above = code=20 works. If he enters the size 100500, the indices exceeds the ranges, = so you=20 may have some problems. Now suppose the user enters 5 as the size of = the arry,=20 then 99995 locations are allocated unnecessarily. Not that defining = arrays=20 with very large sizes is inefficient. So we need dynamic=20 structures.

    Example: Suppose you want to write a program that takes two=20 polynomials from the user. Perform addition and multiplication = operations on=20 them


    #include <stdio.h>
    #define MAX 100
    
    int main(){
       int p1[MAX] =3D {0}, p2[MAX] =3D {0}, result[MAX] =3D {0};
       int i, n;
       printf("enter the degree of first polynom:");
       scanf("%d",&n);
       if (n >=3D MAX)
          return 0;
       printf("enter coefficients:");
       for (i =3D n; i >=3D 0; i--)
          scanf("%d",&p1[i]);
    
       printf("enter the degree of second polynom:");
       scanf("%d",&n);
       if (n >=3D MAX)
          return 0;
       printf("enter coefficients:");
       for (i =3D n; i >=3D 0; i--)
          scanf("%d",&p2[i]);
    
       /* addition */
       for (i =3D 0; i < MAX; i++)
          result[i] =3D p1[i] + p2[i];
      =20
       /* multiplication */
       for (i =3D 0; i < MAX; i++)
          result[i] =3D 0;
       for (i =3D 0; i < MAX; i++)
          for (n =3D 0; n < MAX; n++)
             if (p1[i] * p2[n] !=3D 0)
                result[i + n] +=3D p1[i] * p2[n];
      =20
       anykey();
       return 0;
    }  =20
    
    

14. passing arrays or = pointers to=20 functions

  1. When an array name is passed to a function, what is passed is the = address=20 of the initial element of an array.=20
  2. When a pointer is passed, the address value is passed.=20
  3. Arrays and pointers can be used interchangebly in defining = parameters of=20 functions. We do not need to specify the size of the array in the = parameter=20 list unless it is a multidimensional array.=20
  4. If an address parameter is passed to a function, you can modify = the values=20 pointed by this address and the modifications can be seen after the=20 termination of the function. If you try to change the value of the = parameter,=20 it won' t be seen by the caller part.=20
  5. Functions can also return to pointers, but not arrays! . =

Example: You have integers with size n. You want to change all = elements which are equal to the given integer value with another given = integer.=20 Write a function that performs this operation, and returns to the number = of the=20 changed numbers */


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

int change(int *numbers, int size, int value, int modify_value){
   int i, temp =3D 0;
   for (i =3D 0; i < size; i++)
      if (numbers[i] =3D=3D value){
         numbers[i] =3D modify_value;
         temp++;
      }
      return temp;=20
}

int main(){
   int a[] =3D {2,3,4,5,6,2,2,2,1,3}, k, *p;
   k =3D change(a,10,2,10);
   printf("%d\n",k);
   p=3Da;
   k =3D change(p,10,2,10);
   printf("%d\n",k);
=20
   p =3D (int *)calloc(10,sizeof(int));
   k =3D change(p,10,0,10);
   printf("%d\n",k);
   anykey();
   return 0;
}

Example: Write a function that takes coefficients of a vector = and a=20 scalar, multiplies them, and returns the resultant vector.=20


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

float *multiplication(float *M, int size, float scalar){
   float *result;
   int i;
   result =3D (float *)malloc(size * sizeof(float));
   for (i =3D 0; i < size; i++)
      result[i] =3D M[i] * scalar;
   return result;
}

int main(){
	float *v,*result,scalar;
	int size,i;
	printf("Enter the size of the vector:");
	scanf("%d",&size);
	if(size<=3D0){
		printf("Error: invalid size");
		return -1;
	}=09
	v=3D(float*)malloc(size*sizeof(float));
	if(v =3D=3D NULL){
		printf("Error: not enough memory");
		return -2;
	}
	printf("Enter the values of the vector:");
=09
	for(i=3D0;i<size;++i){
		scanf("%f",&v[i]);
	}
=09
	printf("Enter the scalar value that will be multiplied with the =
vector:");
	scanf("%f",&scalar);
=09
	result =3D multiplication(v,size,scalar);
=09
	printf("original vector you entered:\n");
=09
	for(i=3D0;i<size;++i){
		printf("%f ",v[i]);
	}
	printf("\n");
=09
	printf("resultant vector after multiplication:\n");
=09
	for(i=3D0;i<size;++i){
		printf("%f ",result[i]);
	}
	printf("\n");
=09
	free(v);
	free(result);
=09
	anykey();
	return 0;
}

Example: Write a function that sorts a given array. =


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

void swap(int *a, int *b){
   int temp;
   temp =3D *a;
   *a =3D *b;
   *b =3D temp;
}

void sort_array(int *arr, int size){
   int i, j, temp;
   for (i =3D 0; i < size; i++)
      for (j =3D i + 1; j < size; j++)
         if (arr[i] > arr[j])
            swap(&arr[i],&arr[j]);
}

int main(){
   int *array, size, i;
   printf("Enter the size of the array:\n");
   scanf("%d",&size);
   array =3D (int *)malloc(size * sizeof(int));
   for (i =3D 0; i < size; i++){
      array[i] =3D rand()%10;
      printf("%d\t",array[i]);
   }
   printf("\n");
   sort_array(array,size);
   for (i =3D 0; i < size; i++)
      printf("%d\t",array[i]);
   printf("\n");
   free(array);
  =20
   anykey();
   return 0;
}

Example: Suppose we have a sorted array with size N. Write a = function=20 that finds a given number in this array, and returns the index of its = location.=20 If the number is not found, your function should return -1. Perform = search by=20 using binary search algorithm.


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

void swap(int *a, int *b){
   int temp;
   temp =3D *a;
   *a =3D *b;
   *b =3D temp;
}

void sort_array(int *arr, int size){
   int i, j, temp;
   for (i =3D 0; i < size; i++)
      for (j =3D i + 1; j < size; j++)
         if (arr[i] > arr[j])
            swap(&arr[i],&arr[j]);
}

int BinarySearch(int A[], int number, int N){
   int low =3D 0, high =3D N - 1, mid;
   while (low <=3D high){
      mid =3D (low + high) / 2;
      if (A[mid] =3D=3D number)
         return mid;
      if (A[mid] < number)
         low =3D mid + 1;
      else
         high =3D mid - 1;
   }
   return -1;
}

int main(){
   int *array, size, i, searchedNumber,searchedNumberIndex;
   printf("Enter the size of the array:\n");
   scanf("%d",&size);
   array =3D (int *)malloc(size * sizeof(int));
   for (i =3D 0; i < size; i++){
      array[i] =3D rand()%10;
      printf("%d\t",array[i]);
   }
   printf("\n");
   sort_array(array,size);
   for (i =3D 0; i < size; i++)
      printf("%d\t",array[i]);
   printf("\n");
  =20
   printf("Enter a number for searching within the array:\n");
   scanf("%d",&searchedNumber);
  =20
   searchedNumberIndex =3D BinarySearch(array,searchedNumber,size);
  =20
   if(searchedNumberIndex=3D=3D-1){
	   printf("value not found\n");
   }
   else{
	   printf("value found at index %d\n",searchedNumberIndex);
   }
  =20
   free(array);
  =20
   anykey();
   return 0;
}


15. strings

The string is a memory block whose last element is indicated by the = null=20 character:

'\0'
The null character = provides us to know=20 the end of the block. This feature is important since it is very common = to use=20 texts in our programs. The memory block can be kept as a character array = or its=20 first address is kept in a character pointer. Suppose we have an = character=20 pointer P, not a string. To print its content we must know its size and = the code=20 for this task is:=20

for (i =3D 0; i < size; i++)
	printf("%c",P[i]);

If we use strings, we should set the last element of P to the null = character.=20 Therefore we do not need to keep the value of the size of the block. Our = code=20 becomes:

for (i =3D 0; P[i] !=3D '\0'; i++)
	printf("%c",P[i]);

Actually many facilities for strings can be found in C. For example = printf=20 function can be applied on strings directly, the conversion specifier = for strins=20 is %s. And our code becomes

printf("%s",P);

A string constant can be given in double quotes (remember the string = given in=20 double qutoes in printf function). A string constant "hello world" is an = array=20 of characters. In internal representation, the array is terminated with = the null=20 character, so the program can find the end of the string. The length of = a string=20 is the numbers of characters in a string plus 1, which is for the null=20 character. Let us examine the declaration of strings:

  1. char a[] =3D "blue";
    This declaration creates an array = with size 5 and=20 initializes the contents of array. This is exactly the same as the = first=20 statement of the following code.
    char a[] =3D =
    {'b','l','u','e','\0'};
    a[0] =3D 'a';        /* a becomes "alue" */
    a[2] =3D '+;         /* a becomes "al+e" */
    a[6] =3D '+';        /* you should not try to access the sixth element,=20
                          since this is not an allocated location */
    a[5] =3D '*'         /* it is OK, but you lose the ending point=20
                          information as the result of this statement =
    */

    #include <stdlib.h>
    #include <stdio.h>
    
    int main(){
    	char p[5];=09
    	p[0] =3D 'b';=20
    	p[1] =3D 'l';=20
    	p[2] =3D 'u';
    	p[3] =3D 'e';=20
    	p[4] =3D '\0';
    	printf("%s\n",p);
    	p[1] =3D 'a';            /* we can change the contents of this string =
    */
    	printf("%s\n",p);
    	anykey();
    	return 0;
    }

    Example: Write a function that compute the length of a given = string.=20


    #include <stdlib.h>
    #include <stdio.h>
    
    int stringLength(char str[]){
       int i =3D 0;
       while (str[i] !=3D '\0')
          i++;
       return i;
    }
    
    
    int main(){
    	char str1[] =3D "blue";
    	char str2[] =3D "green";
    	printf("length of str1: %d\n",stringLength(str1));
    	printf("length of str2: %d\n",stringLength(str2));
    =09
    	anykey();
    	return 0;
    }
    =09
    	

    Example: Write a function that copies a source string to the = destination string. You can assume that memory place for the = destination=20 string was allocated previously.


    #include <stdlib.h>
    #include <stdio.h>
    
    void stringCopy(char destination[], char source[]){
       int i =3D 0;
       while (source[i] !=3D '\0'){
          destination[i] =3D source[i];
          i++;
       }
       destination[i] =3D '\0';
    }
    
    int main(){
    	char dest[100], str[]=3D"yellow";
    	stringCopy(dest,str);
    	printf("dest:%s\n",dest);
    =09
    	anykey();
    	return 0;
    }

    Actually, we have useful functions defined in string.h library. Let = us=20 examine some of them.

    1. strlen(char S[]): it returns the number of characters in S, not = counting=20 the null character.=20
    2. strcpy(char dest[], char source[]): it copies the string source = to the=20 string destination. The function stops copying after the null = character has=20 been moved. You must allocate necessary space for dest before = calling this=20 function.
      #include<stdio.h>
      #include<string.h>
      
      int main(){
      	char a[100]=3D"", b[] =3D "cmpe150";
      	int t;
      	t =3D strlen(b);          /* t becomes 7 */
      	printf("t:%d\n",t);=09
      	strcpy(a,b);            /* string b is copied into a,*/
          printf("a:%s\n",a);
      	anykey();
      	return 0;
      }
      

    3. strcmp(char S1[], char S2[]): it compares the strings S1 and S2 = and:
      	returns <0 if S1<S2
      	returns =3D0 if S1=3D=3DS2
      	returns >0 if S1>S2
      For example "abc" < "abd", "dac" > = "cbd", etc.
      #include<stdio.h>
      #include<string.h>
      
      int main(){
      	char s1[]=3D"ali",s2[]=3D"veli",s3[]=3D"aliveli",s4[]=3D"ali";
      =09
      	printf("%d %d %d =
      %d\n",strcmp(s1,s2),strcmp(s2,s1),strcmp(s1,s3),strcmp(s1,s4));
      =09
      	anykey();
      	return 0;
      }

    4. strcat(char dest[], char source[]): appends a copy of source to = the end=20 of dest. You should expand the location for dest before calling this = function.
      #include<stdio.h>
      #include<string.h>
      
      int main(){
      	// set first characters to null character for safety
      	// this is the same as saying:   char a[100]=3D{'\0'}, b[100]=3D{'\0'};
      	char a[100]=3D"", b[100]=3D"";=09
      	strcpy(a,"cmpe");            /* "cmpe" is copied into a */=09
      	strcpy(b,"150");            /* "150" is copied into b */=09
      	printf("before strcat a:%s b:%s\n",a,b);
      	strcat(a,b);
      	printf("after strcat a:%s b:%s\n",a,b);
      	anykey();
      	return 0;
      }
      

    5. gets(char S[]): gets a string of characters terminated by a = newline from=20 the standard input stream, keyboard, and puts in string S. It = replaces a=20 newline by a null character in S. This function is defined in = stdio.h=20 library. You must also allocate space for S.=20
    6. puts(char S[]): copies the null terminated string S to the = standard=20 output stream, monitor, and appends a newline character. It is = defined in=20 stdio.h library.=20
    7. int atoi(char S[]): converts a string S to its corresponding = integer. If=20 the string cannot be converted to an integer it returns zero. It is = defined=20 in stdlib.h library.
      atoi("345") returns an integer 345.=20
      atoi("abc") returns zero.
      atoi("12ad3") returns 12. 
    8. double atof(char S[]): converts a string S to the corresponding = floating=20 number.=20
    9. sprintf: sends formatted output to a string, it is defined in = stdio.h.=20
      #include<stdio.h>
      #include<string.h>
      
      int main(){
      	char str[100];
      	float stdhour =3D 1.5;
      	sprintf(str,"cmpe%d course takes %f hours\n",150,3*stdhour);
      	printf("str:%s\n",str);
      	anykey();
      	return 0;
      }

    10. sscanf: it reads the values from the given string. It is defined = in=20 stdio.h.
      #include<stdio.h>
      #include<string.h>
      
      int main(){
      	int a;
      	float b,c;
      	char str[]=3D"12 3.4 4.2";
      	sscanf(str,"%d%f%f",&a,&b,&c);
      	printf("a:%d b:%f c:%f\n",a,b,c);
      	anykey();
      	return 0;
      }

16. multidimensional arrays =

We can define multidimensional arrays. In the two dimension, = multidimensional=20 arrays provide us to think of the memory locations as a table. Actually = it is=20 not possible to keep a table format for memory locations and two = dimensional=20 array is an one dimensioanl array, whose elements are sorted. In the=20 declaration, we specify all dimensions of the multidimensional array. = Suppose=20 the following two dimensional array declarations:

int a[3][4];  =
                     /* You can think of array a with 3 rows=20
                                      and 4 columns, but actually 12 =
consecutive=20
                                      locations are allocated for the =
elements=20
                                      of a */
int b[3][5] =3D {{0,1,2},{3}};       /* It is also possible to =
initialize the=20
                                      multidimensional arrays, all =
uninitialized=20
                                      locations are set to zero as in =
the single=20
                                      dimensional arrays */
int c[][5] =3D {{1,2},{3,4}};        /* First dimension is set to 2 in =
this case */
int d[][] =3D {{1,2},{3,4},{5,6}};   /* It is illegal, only the first =
dimension=20
                                      can be free, i.e., unspecified */
int e[3][4][5];                    /* It is a three dimensional array, =
actually=20
                                      it consists of 60 consecutive =
int-sized
                                      locations*/

If a two dimensional array is to be passed to a function, what is = passed is a=20 pointer to an array of rows. The parameter declaration in the function = must=20 include the size of dimensions except that of the first one. Suppose the = following function declarations and function calls.

void =
func1(int a[][]){}            /* it is invalid, you need to specify at =
least=20
                                      the second dimension*/
void func2(int a[3][4]){}          /* valid */
void func3(int a[][4]){}           /* valid */
-------------------------------------------------------
int a[3][7], b[5][4], c[3][4];
func3(a);                          /* invalid */
func3(b);                          /* valid */
func3(c);                          /* valid */

Example: Consider a block of 10 apartment houses, each of = which=20 contains 6 apartment flats. First, we want to keep the number of people = in each=20 flat, and then we want to compute the average number of people that live = in each=20 apartment house.


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

void read_number_of_people(int block[][6],int houses,int flats){
   int i, j;
   for (i =3D 0; i < houses; i++)
      for (j =3D 0; j < flats; j++)
         scanf("%d",&block[i][j]);
}
void find_total(int block[][6], int total[],int houses, int flats){
   int i, j;
   for (i =3D 0; i < houses; i++){
      total[i] =3D 0;
      for (j =3D 0; j < flats; j++)
         total[i] +=3D block[i][j];
   }
}
int main(){
   int apt_block[10][6], apt_total[10];
   read_number_of_people(apt_block,10,6);
   find_total(apt_block,apt_total,10,6);
  =20
   for(int i=3D0;i<10;i++){
	   printf("%d ",total[i]);
   }
  =20
   anykey();
   return 0;
}

Example: We have two two-dimensional matrices whose dimensions = are=20 2x4. Write a function for computing the sum of these two matrices. Write = another=20 function to compute the transpose of a give matrix.


#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 4

void matrix_sum(int x1[][MAX_SIZE], int x2[][MAX_SIZE], int =
result[][MAX_SIZE], int row, int column){
   int i, j;
   for (i =3D 0; i < row; i++)
      for(j =3D 0; j < column; j++)
         result[i][j] =3D x1[i][j] + x2[i][j];
}

void matrix_transpose(int m[][MAX_SIZE], int T[][MAX_SIZE], int row, int =
column){
   int i, j;
   for (i =3D 0; i < row; i++)
      for(j =3D 0; j < column; j++)
         T[j][i] =3D m[i][j];
}

void print_matrix(int m[][MAX_SIZE],int row, int column){
	int i,j;
	for(i=3D0;i<row;i++){
		for(j=3D0;j<column;j++){
			printf("%d ",m[i][j]);
		}
		printf("\n");
	}
}

void random_fill(int m[][MAX_SIZE],int row, int column){
	int i,j;
	for(i=3D0;i<row;i++){
		for(j=3D0;j<column;j++){
			m[i][j]=3Drand()%10;
		}
	}
}


int main(){
   int m1[MAX_SIZE][MAX_SIZE], m2[MAX_SIZE][MAX_SIZE], =
result[MAX_SIZE][MAX_SIZE], m3[MAX_SIZE][MAX_SIZE], =
transpose_m3[MAX_SIZE][MAX_SIZE];
   random_fill(m1,2,4);
   random_fill(m2,2,4);
   random_fill(m3,3,4);
   printf("m1:\n");
   print_matrix(m1,2,4);
   printf("m2:\n");
   print_matrix(m2,2,4);  =20
   matrix_sum(m1,m2,result,2,4);
   printf("m1+m2:\n");
   print_matrix(result,2,4);
   printf("m3:\n");
   print_matrix(m3,3,4);
   matrix_transpose(m3,transpose_m3,3,4);
   printf("transpose of m3:\n");
   print_matrix(transpose_m3,4,3);
   anykey();
   return 0;
}

Example: Consider we have 5 classes, each of which has 30 students. = These 30=20 students takes 10 course (all students in different classes take the = same=20 courses).=20

  1. Write a function that takes grades of each student from the user.=20
  2. Write a function that computes the average of 10 courses.=20
  3. Write a function that assigns letter grades to the given grades of = the=20 students (90 - 100: A, 80 - 89: B, 70 - 79: C, 60 - 69: D, 0 - 59: F, = and=20 assume all grades are given between 0 and 100).


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

#define NUM_CLASSES 3
#define NUM_STUDENTS 4
#define NUM_COURSES 2

void read_grades(float grades[][NUM_STUDENTS][NUM_COURSES],=20
   int classes, int students, int lessons){
   int i, j, k;
   for (i =3D 0; i < classes; i++)
      for (j =3D 0; j < students; j++)
        for (k =3D 0; k < lessons; k++){
			printf("Enter the grade for class:%d student:%d lesson %d: ",i,j,k);
            scanf("%f",&grades[i][j][k]);
		}
}
void compute_avg_lessons(float avg[],float =
grades[][NUM_STUDENTS][NUM_COURSES],=20
   int classes, int students, int lessons){
   int i, j, k;
   for (i =3D 0; i < lessons; i++){
      avg[i] =3D 0.0;
      for (j =3D 0; j < classes; j++)
         for (k =3D 0; k < students; k++)
            avg[i] +=3D grades[j][k][i];
         avg[i] /=3D classes * students;
   }
}
void give_letter_grades(char letter_grades[][NUM_STUDENTS][NUM_COURSES], =

   float grades[][NUM_STUDENTS][NUM_COURSES],int classes,int =
students,int lessons){
   int i, j, k;
   for (i =3D 0; i < classes; i++)
      for (j =3D 0; j < students; j++)
         for (k =3D 0; k < lessons; k++)
            switch((int)(grades[i][j][k] / 10)){
               case 10: case 9: letter_grades[i][j][k] =3D 'A';=20
                  break;
               case 8: letter_grades[i][j][k] =3D 'B';=20
                  break;
               case 7: letter_grades[i][j][k] =3D 'C';=20
                  break;
               case 6: letter_grades[i][j][k] =3D 'D';=20
                  break;
               default: letter_grades[i][j][k] =3D 'F';=20
                  break;
            }
}

void print_float_array(float arr[], int size){
	int i;
	for(i=3D0;i<size;i++){
		printf("%f ",arr[i]);
	}
	printf("\n");
}

void print_3D_char_array(char arr[][NUM_STUDENTS][NUM_COURSES],int =
depth,int rows,int columns){
	int i,j,k;
	for(i=3D0;i<depth;i++){
		printf("%d:\n",i);
		for(j=3D0;j<rows;j++){
			for(k=3D0;k<columns;k++){
				printf("%c ",arr[i][j][k]);
			}
			printf("\n");
		}
	}
}

int main(){
   float grades[NUM_CLASSES][NUM_STUDENTS][NUM_COURSES], =
avg_courses[NUM_COURSES];
   char letters[NUM_CLASSES][NUM_STUDENTS][NUM_COURSES];
  =20
   read_grades(grades,NUM_CLASSES,NUM_STUDENTS,NUM_COURSES);
   =
compute_avg_lessons(avg_courses,grades,NUM_CLASSES,NUM_STUDENTS,NUM_COURS=
ES);
   print_float_array(avg_courses,NUM_COURSES);
  =20
   =
give_letter_grades(letters,grades,NUM_CLASSES,NUM_STUDENTS,NUM_COURSES);
   print_3D_char_array(letters,NUM_CLASSES,NUM_STUDENTS,NUM_COURSES);
  =20
   anykey();
   return 0;
}

Remember arrays have a major drawback: They cannot be created and = used=20 dynamically. We saw that we can use pointers as one dimensional arrays, = we can=20 also use pointers for higher dimensions.

17. structures

A structure is a collection of one or more variables, whose = data types=20 can be different, under a single name. They are derived data types.

Example: Suppose you want to keep lines in your program. To = this end,=20 you want to create a line by taking its two endpoints. You also want to = perform=20 the swapping operations on some points and you want to calculate the = length of a=20 given line.


#include <stdio.h>
#include <math.h>

struct point {
   int x;
   int y;
};

struct line{
   struct point p1;
   struct point p2;
};

struct point makePoint(int a, int b){
   struct point temp;
   temp.x =3D a;
   temp.y =3D b;
   return temp;
}

void swapPoints(struct point *p, struct point *r){
   struct point temp;
   temp =3D *p;
   *p =3D *r;
   *r =3D temp;
}

float lenght(struct line L){
   float d;
   d =3D sqrt((L.p1.x - L.p2.x) * (L.p1.x - L.p2.x) +
       (L.p1.y - L.p2.y) * (L.p1.y - L.p2.y));
   return d;
}

void printPoint(struct point p){
	printf("p.x:%d p.y:%d\n",p.x,p.y);
}

int main(){
   struct point a, b;
   struct line L;
   float k;

   a =3D makePoint(0,0);
   b =3D makePoint(3,4);
  =20
   printf("point a:");
   printPoint(a);
   printf("point b:");
   printPoint(b);
  =20
   swapPoints(&a,&b);
  =20
   printf("point a after swap:");
   printPoint(a);
   printf("point b after swap:");
   printPoint(b);
  =20
   L.p1 =3D a;
   L.p2 =3D makePoint(6,8);
   k =3D lenght(L);
  =20
   printf("length is %f\n",k);
  =20
   anykey();
   return 0;
}

It is also possible to nest the structures as you can see above. = Consider=20 also the following examples:

struct point{
   int x;
   int y;
};
struct line{
   struct point p1;
   struct point p2;
};
struct circle{
   struct point center;
   float radius;
};
  1. Valid operators=20
    1. You can access the members of a structure. To access a member: =
      structure_name.member_name
      For example:
      struct point{
         float x;
         float y;
      };
      struct point p, *p_ptr, p_arr[10];
      
      p_ptr=3D&p;
      p.x =3D 4;
      (*p_ptr).y=3D5;
      p_ptr->y=3D5; // this is the same as above statement.=20
      *p_ptr.y=3D5; // illegal. You must use one of the above two
      
      p_arr[2].x=3D12;
      p_arr[0].y=3D4.5;
      
    2. It is valid to copy the structure variables of the same data = type. The=20 following copying operations are all valid.
      struct point{
         int X, Y;
      };
      struct line{
         struct point P1, P2;
      };
      
      struct line L, K;
      struct point p1;
      
      L.P1.X =3D 3;
      L.P1.Y =3D 4;
      p1.X =3D 5;
      p1.Y =3D 7;
      L.P2 =3D p1;
      K =3D L;
      L.P2 =3D K.P1;
    3. Taking the address of a structure variable is valid
  2. Array of structures and structure pointers=20

    As you recall from the point example above, struct pointer and = array of=20 structures is valid

  3. Typedef=20

    It creates new data types. For example:

    typedef int =
    length;

    makes the name of length a synonym for int. And both=20 declarations of a variable with the integer data type are valid. =

    int len1;
    length len2;

    But typedef is usually necessary for complicated types. =

    struct polynom{
       int degree;
       float coeff[100];
    };
    
    typedef struct polynom poly;
    /* from now on
    for declaring a polynom variable,
    you can both use:
       struct polynom p;
    or
       poly p;
    */
    
  4. Structure and functions=20
    1. You pass the entire structures or members (call by value).=20
    2. You pass the address of the structure (call by reference).=20
    3. Your function can return a structure or pointer to structure. =

    Example: In this example, you are supposed to implement the = basic=20 operations on polynomials. Write a program that includes the necessary = definition for a polynomial, and the following functions.

    1. Read the coefficients of a polynomial from the user.=20
    2. Print the coefficients of a polynomial.=20
    3. Perform the addition of two polynomials.

    #include <stdio.h>
    #include <stdlib.h>
    
    
    struct polynomial{
       int degree;
       float coeff[100];
    };
    typedef struct polynomial poly;
    
    
    void read_poly(poly *p){
       int i;
       printf("Enter the degree of the polynom:");
       scanf("%d",&(p->degree));
       for (i =3D p->degree; i >=3D0; i--){
          printf("Enter coefficient for degree %d: ",i);
          scanf("%f",&(p->coeff[i]));
       }
    }
    void print_poly(poly p){
       int i;
       for (i =3D p.degree; i > 0; i--){
          if (p.coeff[i] !=3D 0){
             printf("%f x^%d + ",p.coeff[i],i);
    	  }
       }
       printf("%f\n",p.coeff[0]);
    }
    poly addition(poly p1, poly p2){
       poly temp;
       int max, i;
       if (p1.degree > p2.degree)
          max =3D p1.degree;
       else
          max =3D p2.degree;
       temp.degree=3Dmax;
       for (i =3D 0; i <=3D temp.degree; i++){
          temp.coeff[i] =3D 0.0;
          if (p1.degree >=3D i)
             temp.coeff[i] +=3D p1.coeff[i];
          if (p2.degree >=3D i)
             temp.coeff[i] +=3D p2.coeff[i];
       }
       return temp;
    }
    
    int main(){
       poly p1, p2, p3;
      =20
       read_poly(&p1);
       read_poly(&p2);
       p3 =3D addition(p1,p2);
    
       print_poly(p1);
       print_poly(p2);
       print_poly(p3);
      =20
       anykey();
       return 0;
    }
    

18. advanced c topics

  1. Bitwise operators=20

    Table 3: Bitwise operators

    & bitwise and
    | bitwise or
    ^ bitwise exclusive or
    << bitwise left shift
    >> bitwise right shift
    ~ bitwise one's complement (unary=20 operator)
    int a, b, c;
    a =3D 10; b =3D 86;  /*a =3D 1010, b =3D 1010110*/
    c =3D a & b;       /*c =3D 0000010 =3D 2*/
    c =3D a | b;       /*c =3D 1011110 =3D 94*/
    c =3D a ^ b;       /*c =3D 1011100 =3D 92*/
    c =3D b << 1;      /*c =3D 10101100 =3D 172, it is same as b*2*/
    c =3D b << 2;      /*c =3D 101011000 =3D 344, it is same as =
    b*2^2*/
    c =3D b >> 1;      /*c =3D 101011 =3D 43, it is same as b/2*/
    c =3D b >> 2;      /*c =3D 10101 =3D 21, it is same as b/2^2*/
    c =3D ~b;          /*c =3D -87*/
  2. Relationship Between Arrays and Pointers: dynamic memory = allocation with=20 malloc,calloc and realloc=20

    When we declare int a[10];, a block consists of 10 consecutive = places, each=20 is capable of storing an integer, is allocated. After this = declaration, we=20 cannot change the size of the allocated block, i.e. we can neither = expand the=20 block nor shrink it. Our aim is to allocate a block in the memory such = that=20 its size can be changed in the program execution.

    To this end, let us first examine the relationship between pointers = and=20 arrays and their notations. Suppose the following declarations: =

    int myArray[10];
    int *myPointer;

    We know that myArray is the name of the 10 individual elements, it = is NOT a=20 variable. Actually myArray (the name of an array) is a synonym for the = address=20 of the initial element of an array, &a[0]. We know that myPointer = is a=20 variable that is capable of storing an address in it. Thus, if we want = to=20 store the address of the first element of myArray into myPointer, the=20 following two statements are equivalent:

    myPointer =3D =
    &myArray[0];
    myPointer =3D myArray;

    So you can use the notations of pointers and arrays interchangebly. = The=20 following usages are equivalent:

    	myArray[i]	  ≡	=
    *(myArray+i)
    	myArray+i	   ≡	&myArray[i]
    	myPointer[i]	≡ 	*(myPointer+i)
    	myPointer+i	 ≡	&myPointer[i]

    Please remember their differences again. A pointer is a variable, = i.e., it=20 is kept in some memory locations. Thus myPointer=3DmyArray or = myPointer++ are=20 legal statements. But array name is not a variable and = myArray=3DmyPointer or=20 myArray++ are ILLEGAL statements. And also remember that we should not = access=20 the memory locations that are not allocated before. This rule is valid = for=20 both arrays and pointers.

    Exercise: Trace the following code and observe the = consequence of=20 each statement.


    #include<stdio.h>
    
    int main(){
       int a[] =3D {2, 20, 3, 1, -1, -6}, *p, t;
       p =3D &a[0];          /* In p is the address of the initial =
    element of a */
       printf("p:%d a:%d &a[0]:%d a:%d\n",p,a,&a[0],a);
       t =3D *p;             /* t becomes 2 */
       printf("t:%d\n",t);
       t =3D *(p + 1);       /* t becomes 20 */
       printf("t:%d\n",t);
       p =3D p + 3;          /* In p is the address of the third element of =
    a*/
       printf("p:%d\n",p);
       t =3D *p;             /* t becomes 1 */
       printf("t:%d\n",t);
       t =3D a[2];           /* t becomes 3 */
       printf("t:%d\n",t);
       t =3D *(a + 2);       /* t becomes 3 */
       printf("t:%d\n",t);
       p =3D a;              /* In p is the address of the initial element =
    of a */
       printf("p:%d\n",p);
       p++;                /* Increments the value of p */
       printf("p:%d\n",p);
       t =3D *p;             /* t becomes 20 */
       printf("t:%d\n",t);
       t =3D p[2];           /* t becomes 1 */
       printf("t:%d\n",t);
       t =3D p[-1];          /* t becomes 2 (t can be 3 at other compilers, =
    which convert negative indexes to its positive counterpart) */
       printf("t:%d\n",t);
       a =3D p;              /* illegal, since a is not the variable, =
    comment out this line for successful compile*/
       a++;                /* illegal, since a is not the variable, comment =
    out this line for successful compile*/
       anykey();
       return 0;
    }
    

    So we have seen that we can use arrays and pointers interchangebly. = Remember our problem, we want to change the size of the allocated = block during=20 the execution of our program. In the declaration of an array, an = appropriate=20 memory block is allocated implicitly and we cannot change its size. It = is=20 possible to change the size of an allocated block only we perform our=20 allocations explicitly. There are three types of allocation functions = defined=20 in stdlib.h.

    1. malloc: It allocates a block of bytes from memory. The = size of=20 the allocated block is given as the argument to the function. On = success, it=20 returns the beginning address of the newly allocated block. It = returns NULL=20 on error, e.g., if there is not enough memory.
      int *a;
      a =3D (int *)malloc(8 * sizeof(int));

      In this example, the size of the block is 8*sizeof(int), which = means we=20 allocate a block in which we can keep 8 integers. Note that the size = of the=20 integer or any data type varies from computer to computer. = sizeof(int)=20 returns the size of the specified argument in bytes, in our example = it=20 returns how much byte is necessary to keep an integer in the = computer which=20 our program runs. The result of this function may be different for = different=20 computers. There are other malloc examples:

      double =
      *numbers, char *letters;
      numbers =3D (double *)malloc(348 * sizeof(double));
      letters =3D (char *)malloc(100 * sizeof(char));
    2. calloc: It allocates a memory block like malloc, the = difference=20 is that calloc sets the memory to zero. The syntax of calloc is = illustrated=20 in the following example:
      long *elements;
      elements =3D (long *)calloc(348, sizeof(long));
    3. realloc: It adjusts the size of the allocated block to = its new=20 size, copying the contents to a new location, if necessary. On = success, it=20 returns the address of the beginning of the reallocated block, which = might=20 be different of the original block. On failure, realloc function = returns=20 NULL.
      vector =3D (long *)realloc(vector, 4 * =
      sizeof(long));
      It adjusts the=20 size of vector to 4 and returns the beginning address of a newly = allocated=20 block. Realloc is applied to the blocks either previously obtained = by=20 malloc/calloc/realloc or set to NULL. Otherwise undefined behaviors = may=20 occur.

    Example: Write a program that takes the decimal numbers from = the=20 user and computes their average. The number of decimal numbers is = specified by=20 the user at the beginning of the program. In this example, we do not = know the=20 size of the numbers when we write our program. Therefore we allocate = space for=20 the numbers in the execution, which requires explicit allocation. =


    #include <stdlib.h>
    #include <stdio.h>
    
    int main(){
       int size, i;
       float *elements, avg;
       printf("Enter the amount of the numbers:");
       scanf("%d",&size);
       if (size <=3D 0){
          printf("The size must be positive\n");
          exit(1)
       }
       elements =3D (float *)malloc(size * sizeof(float));
       if (elements =3D=3D NULL){
          printf("Not enough memory space\n");
          exit(1);
       }
       for (i =3D 0; i < size; i++)
          scanf("%f",&elements[i]);
       avg =3D 0.0;
       for (i =3D 0; i < size; i++)
          avg +=3D elements[i];
       avg / =3D size;
       free(elements);
       anykey();
       return 0;
    }
    

    We know that variables are deallocated, i.e., freed, when we exit = their=20 scopes. In this example variables size, i, elements adn avg are = deallocated at=20 the end of the program. Since we allocate the memory block explicitly, = we=20 should also perform the deallocation of this block explicitly. free = function=20 deallocates a memory block allocated by a previous allocation = function, i.e.,=20 malloc, calloc or realloc. If you try to free the memory block that = was not=20 allocated before, undefined behavior occurs.

    Example: Write a program that takes the decimal numbers from = the=20 user until a negative value is entered and computes their average. In = this=20 example, we do not know the size of the necessary block neither before = the=20 executin nor during the execution. We can only know the exact size = when a=20 negative value is entered. Therefore in this example, we assume the = size of=20 the block is 0 at the beginning of the program, then we expand the = block=20 incremently. So we use realloc function.


    #include <stdlib.h>
    #include <stdio.h>
    
    int main(){
       int counter =3D 0, i;
       float *elements, avg, temp;
       elements =3D NULL;              /* This is necessary to use the =
    realloc=20
                                        function in a safe way later */
       scanf("%f",&temp);
       while (temp >=3D 0){
          counter++;
          elements =3D (float *)realloc(elements,counter * sizeof(float));
          if (elements =3D=3D NULL){
             printf("Error in the allocation\n");
             exit(1);
          }
          elements[counter - 1] =3D temp;
          scanf("%f",&temp);
       }
       if (counter =3D=3D 0)
          printf("There is no number\n");
       else{
          for (i =3D 0; i < counter; i++)
             avg +=3D elements[i];
          avg / =3D counter;
       }
       free(elements);
      =20
       anykey();
       return 0;
    }
    

    Do not forget that, crashes are related overflowing an allocated = chunk,=20 using realloc function without initializing its address argument or = freeing=20 the same pointer twice. Also accessing the unallocated memory place = may result=20 in crashes. Consider the following statements and their validity. =

    #include <stdlib.h>
    int main(){
       int *a =3D NULL, *b, *c, *d, *e;
       a =3D (int *)realloc(a, 3*sizeof(int));   /* (1) */
       b =3D (int *)realloc(b, 3*sizeof(int));   /* (2) */
       c =3D (int *)realloc(a, 3*sizeof(int));   /* (3) */
       d =3D (int *)malloc(3*sizeof(int));       /* (4) */
       d =3D (int *)realloc(d, 8*sizeof(int));   /* (5) */
       d =3D (int *)realloc(d, 1*sizeof(int));   /* (6) */
       free(c);                                /* (7) */
       free(a);                                /* (8) */
       free(a);                                /* (9) */
       free(e);                                /* (10) */
       d =3D (int *)malloc(50*sizeof(int));      /* (11) */
       free(d);                                /* (12) */
       d =3D (int *)malloc(50*sizeof(int));      /* (13) */
       free(d);                                /* (14) */
       return 0;
    }

    Let us examine each case.

    (1): it is safe, since a was initialized by NULL in the declaration =
    (2): it results in crashes. Variable b was neither initialized by = NULL nor=20 allocated previously
    (3): it is safe since variable a was = allocated=20 previosly, in (1). Be careful of this statement, the variable a keeps = the=20 address, which indicates the block to be expanded. On the other hand, = the=20 variable c just keeps the return value of the realloc function. =
    (4): it is=20 safe, d points to an allocated block of 3 integers after this = statement.=20
    (5): it makes the size of the allocated block indicated by d = eight. And it=20 is safe since variable d was allocated by malloc in (4) previously. =
    (6):=20 it makes the size of the allocated block indicated by d one. And it is = safe=20 since variable d was allocated by realloc in (5) previously.
    (7): = it is=20 safe, since c was allocated before, in (3).
    (8): it is safe, since = a was=20 allocated before, in (1).
    (9): it is not safe, since a was freed = in (8),=20 and has not been allocated again. So do not try to deallocate the = unallocated=20 memory locations.
    (10): it is not safe, since variable e was not = allocated=20 before.
    (11): it is safe, it is just an allocation. But the = drawback of=20 this allocation is that: we allocate some space and we keep the = starting=20 address of this space in the variable d. When we allocate this = variable again,=20 it begins to keep the address of the newly allocated space, and we = cannot=20 access the space allocated previously any more.
    (12): it is safe, = since d=20 keeps the adress of the allocated memory location, where allocation = was done=20 in (11).
    (13): it is safe, it is just an allocation.
    (14): it = is safe,=20 since we allocate the variable d in (13).

    
      

    In general, a pointer can be initialized as:

    1. by using NULL.
      int *a; long *b =3D NULL;
      a =3D NULL;
    2. by using the expressions involving the addresses of previously = defined=20 data of the appropriate type.
      double *a, b[100], c;
      a =3D &c;
      a =3D b + 2;
    3. by using allocation functions, malloc, realloc or calloc. =

    The valid pointer operations are summarized as follows:

    1. Assignment of addresses or pointers of the same type.=20
    2. Adding or subtracting a pointer and an integer.=20
    3. Subtracting two pointers of the same data type.
      float *a, =
      *b, c[10], t;
      a =3D c; b =3D c + 3;
      t =3D b - a;         /* in this example, t becomes 3 */
    4. Comparing two pointers. Suppose we have pointers p and q. p<q = gives=20 true if p keeps an address smaller than that of kept in q. In the = above=20 example a<b gives true and a>b gives false. It is also = possible to use=20 <=3D,>=3D,!=3D,=3D=3D with pointers.
  3. Advanced String Functions=20

    char *strtok(char *S1, char *S2): scans S1 for the first token not=20 contained in S2. In the firts call, it returns a poinetr to the first=20 character of the first token in S1 and writes a null character into S1 = immediately following the returned token. Be careful in using this = function,=20 since the string S1 is changed after calling this function. =


    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define maxsize 100
    
    int main(){
       char S[maxsize], *temp;
       char *token =3D " ,\t";
       int *numbers =3D NULL, i =3D 0;
       gets(s);
       temp =3D strtok(s,token);
       while (temp !=3D NULL){
          numbers =3D (int *)realloc(numbers,(i + 1) * sizeof(int));
          numbers[i] =3D atoi(temp);
          i++;
          temp =3D strtok(NULL,token);
       }
       free(temp);
       free(numbers);
      =20
       anykey();
       return 0;
    }
    

    EXERCISE: What does the following functions=20 do?
    HINTS:
    The ascii code of '\0' is 0
    The precedence = of ++ is=20 higher than *


    #include<stdio.h>
    
    int f1(char *str){
    	int i=3D-1;
    	while(str[++i]);
    	return i;
    }=20
    
    
    void f2(char *s1, char* s2){
    	while(*s1++=3D*s2++);
    }=20
    
    void f3( char* s1, char* s2 ){
         while (*s1) s1++;
         while (*s1++ =3D *s2++);
    }
    
    
    int main(){=09
    	 =20
        anykey();
        return 0;
    }

  4. Array of Pointers=20

    Suppose there are 100 students in the class and we want to keep = their=20 names. So we can define a two-dimensional character array with = dimensions 100=20 MAX, where MAX is the maximum length of a name possible. So the = declaration is=20 as follows providing a constant MAX was defined before.

    char =
    names[100][MAX];

    In this case there is a waste of space since the length of the = names vary.=20 So instead of keeping each name in an array with size MAX, we can = allocate a=20 memory block with an appropriate size and keeps the starting address = of this=20 block in a pointer. Thus we have an array with size 100 and in each of = its=20 elements an address is kept. The declaration of this array is as = follows:

    char *names[100];

    This array can be considered as a two-dimensional array whose first = dimension is fixed and second dimension is free. And for the second = dimension=20 MEMORY ALLOCATION must be done! Suppose we take the names from the = user and=20 store them in names array.


    #include =
    <stdio.h>
    #include <stdlib.h>
    
    #define NUM_NAMES 5
    #define MAX_NAME_LENGTH 50
    
    int main(){
       char temp[MAX_NAME_LENGTH+1], *names[NUM_NAMES];
       int i;
       printf("Enter %d names:\n",NUM_NAMES);
       for (i =3D 0; i < NUM_NAMES; i++){
          gets(temp);
          names[i] =3D (char *)malloc((strlen(temp) + 1)*sizeof(char));
          strcpy(names[i],temp);
       }
      =20
       printf("names read:\n");
       for(i=3D0; i<NUM_NAMES;i++){
    	   printf("%s\n",names[i]);
       }
      =20
       // we must deallocate the memory:
       for(i=3D0; i<NUM_NAMES;i++){
    	   free(names[i]);
       }
      =20
       anykey();
       return 0;
    }
    
    

    Note that we can also use calloc or realloc function in the memory=20 allocation.

    names[4] =3D (char *)calloc(40, sizeof(char));
    names[57] =3D (char *)realloc(names[57],50 * sizeof(char));

    Example: Suppose we want to keep our payments for each = month.=20

    1. Write a function that takes the payments from the user. For each = month,=20 the number of payments is read first.=20
    2. Write a function that computes and returns the total payment for = each=20 month.

    #include =
    <stdio.h>
    #include <stdlib.h>
    
    #define NUM_MONTHS 12
    
    int *readPayments(int *payments[NUM_MONTHS]){
       int *numberOfPayments =3D (int*)malloc(NUM_MONTHS * sizeof(int)), i, =
    j, temp;
       for (i =3D 0; i < NUM_MONTHS; i++){
          printf("Enter the number of payments of month %d: ",i+1);
          scanf("%d",&temp);
          if (temp < 0){
             printf("The minimum number of payment can be zero\n");
             temp =3D 0;
          }
          numberOfPayments[i] =3D temp;
          if (numberOfPayments[i] !=3D 0){
    	     =20
             payments[i] =3D (int *)malloc(numberOfPayments[i] * =
    sizeof(int));
             for (j =3D 0; j < numberOfPayments[i]; j++){
    	     	printf("Enter payment %d of month %d: ",j+1,i+1);
             	scanf("%ld",&payments[i][j]);
         	}
          }
       }
       return numberOfPayments;
    }
    int *computeTotalPayments(int *payments[NUM_MONTHS], int *no){
       int *total =3D (int *)malloc(NUM_MONTHS * sizeof(int));
       int i, j;
       for (i =3D 0; i < NUM_MONTHS; i++){
          total[i] =3D 0;
          for (j =3D 0; j < no[i]; j++)
             total[i] +=3D payments[i][j];
       }
       return total;
    }
    
    void printArray(int arr[],int size){
    	int i;
    	for(i=3D0;i<size;i++){
    		printf("%d ",arr[i]);
    	}
    	printf("\n");
    }
    
    int main(){
    	int *payments[NUM_MONTHS],*numberOfPayments,*totalPayments,i;
    	numberOfPayments =3D readPayments(payments);
    	totalPayments =3D computeTotalPayments(payments,numberOfPayments);
    =09
    	printf("number of payments each month:\n");
    	printArray(numberOfPayments,12);
    =09
    	printf("total payments each month:\n");
    	printArray(totalPayments,12);
    =09
    	free(numberOfPayments);
    	free(totalPayments);
    	for(i=3D0;i<NUM_MONTHS;i++){
    		free(payments[i]);
    	}
    =09
    	anykey();
    	return 0;
    }

    Note that it is also possible to define pointers to arrays. = In this=20 case, the second dimension is fixed and the first dimension is free. = The=20 declaration, allocation and deallocation of pointers to arrays with = type long=20 are follows:

    long (*powers)[10];
    powers =3D (*(long)[10])malloc(8 * sizeof(long[10]));
    powers =3D (*(long)[10])realloc(powers,4 * sizeof(long[10]));
    free(powers);
  5. Pointers to Pointers=20

    Suppose we want to write matrix multiplication, remember we defined = a=20 matrix as a two-dimensional array last week. But we do not want to = restrict=20 ourselves for fixed dimensions, i.e., we want the first and the second = dimensions to be free. Thus we should allocate memory blocks for both=20 dimensions explicitly. In the same manner the deallocation of both = dimensions=20 is our responsibility. Suppose the following declaration: =

    char **myPointer;

    myPointer is a variable that keeps a single value in it. This value = is an=20 address value, let us call this address M1. When we access the memory = location=20 with address M1, we expect to get another address value, say M2. And = when we=20 access the memory location with address M2, we expect to obtain a = value with a=20 character data type.

    Note that if we want to create a two-dimensional structure in a = function=20 and to return it at the end of the function, we can only use pointers = to=20 pointers as in the allocation, multiplication, etc. functions in the = following=20 examples.

    Example: Perform the following operations on matrices with = varied=20 row and column size.

    1. Allocate necessary space for a matrix with the specified = dimensions.=20
    2. Deallocate the given matrix=20
    3. Print the contents of the matrix in a tabular format.=20
    4. Add two matrices and return the resultant matrix.=20
    5. Multiply two matrices return the resultant matrix.=20
    6. Find the transpose of a given matrix.=20
    7. Generate random elements for a given matrix. Use rand function = to=20 generate the integers between 0 and 99, and assign these values to a = matrix.=20
    8. Use all these functions in a main function.=20
    9. Run these codes and see the results as an exercise. =

    #include <stdio.h>
    #include <stdlib.h>
    
    int **allocate_matrix(int row, int column){
       int **temp, i;
       temp =3D (int **)malloc(row * sizeof(int *));
       for (i =3D 0; i < row; i++)
        temp[i] =3D (int *)malloc(column * sizeof(int));
       return temp;
    }
    void free_matrix(int **M, int row){
       int i;
       for (i =3D 0; i < row; i++)
          free(M[i]);
       free(M);
    }
    void print_matrix(int **M, int row, int column){
       int i, j;
       for (i =3D 0; i < row; i++){
          for (j =3D 0; j < column; j++)
             printf("%d\t",M[i][j]);
          printf("\n");
       }
       printf("\n");
    }
    int **matrix_addition(int **M1, int **M2, int row, int column){
       int i, j, **temp =3D allocate_matrix(row,column);
       for (i =3D 0; i < row; i++)
          for (j =3D 0; j < column; j++)
             temp[i][j] =3D M1[i][j] + M2[i][j];
       return temp;
    }
    int **matrix_multiplication(int **M1, int **M2, int row1, int column1, =
    int column2){
       int **temp =3D allocate_matrix(row1,column2), i, j, k;
       for (i =3D 0; i < row1; i++)
          for (j =3D 0; j < column2; j++){
             temp[i][j] =3D 0.0;
             for (k =3D 0; k < column1; k++)
                temp[i][j] +=3D M1[i][k] * M2[k][j];
          }
       return temp;
    }
    int **matrix_transpose(int **M, int row, int column){
       int i, j;
       int **temp =3D allocate_matrix(column,row);
       for (i =3D 0; i < row; i++)
          for (j =3D 0; j < column; j++)
             temp[j][i] =3D M[i][j];
       return temp;
    }
    void random_matrix(int **M, int row, int column){
       int i, j;
       for (i =3D 0; i < row; i++)
          for (j =3D 0; j < column; j++)
             M[i][j] =3D rand() % 100;
    }
    int main(){
       int **M1, **M2, **result;
      =20
       M1 =3D allocate_matrix(3,4);
       random_matrix(M1,3,4);
       printf("M1:\n");
       print_matrix(M1,3,4);
      =20
      =20
       M2 =3D allocate_matrix(3,4);
       random_matrix(M2,3,4);
       printf("M2:\n");
       print_matrix(M2,3,4);
    
       result =3D matrix_addition(M1,M2,3,4);
       printf("M1+M2:\n");
       print_matrix(result,3,4);
    
       free_matrix(M2,3);
       free_matrix(result,3);
      =20
          M2 =3D allocate_matrix(4,2);
       random_matrix(M2,4,2);
       printf("M2:\n");
       print_matrix(M2,4,2);
    
       result =3D matrix_multiplication(M1,M2,3,4,2);
       printf("M1*M2:\n");
       print_matrix(result,3,2);
    
       free_matrix(M2,4);
       M2 =3D matrix_transpose(result,3,2);
       printf("(M1*M2)^T:\n");
       print_matrix(M2,2,3);
    
       free_matrix(M1,3);
       free_matrix(M2,2);
       free_matrix(result,3);
      =20
       anykey();
       return 0;
    }
    
    

  6. When do you use multidimensional arrays array of pointers and = pointers of=20 pointers=20
    1. Suppose the following problem. We want to keep the distances = between the=20 cities of Turkey. We know there are 81 cities, therefore we can keep = them in=20 a static structure, i.e., by using two-dimensional array. float=20 distances[81][81]; In this declaration, allocation is done = implicitly and=20 after exiting the scope of this array deallocation will be performed = implicitly too. You do not need to allocate and deallocate a memory = block=20 for this array.=20
    2. Suppose we want to keep the distances from a city to its towns = for each=20 city in Turkey. We know that there are 81 cities in Turkey, it is = fixed at=20 this moment. On the other hand different cities may have different = number of=20 towns, thus the number of towns is not fixed. In this example we can = keep 81=20 address information in an array, where each of address indicates the = starting point of a memory block for the corresponding city. In a = memory=20 block, we keep the distances from the city to its towns.
      float =
      *distances[81];
      In this declaration, the allocation of the=20 first dimension is done implicitly. However if we need, we must = allocate the=20 space for the second dimension explicitly by using any allocation = functions.=20 In the same manner when we exit from the scope of distances, the = first=20 dimension will be allocated automatically but we must free the = second=20 dimension.
      /* code for allocation */
      for (i =3D 0; i < 81; i++){
         printf("Enter the number of towns of city %d: ", i);
         scanf("%d",&n);
         distance[i] =3D (float *)malloc(n * sizeof(float));
      }
      /* code for deallocation */
      for (i =3D 0; i < 81; i++)
         free(distance[i]);
    3. Suppose user enters some city numbers. And we only want to keep = the=20 distances between these cities and their towns. In this case we know = neither=20 the number of cities nor the number of towns, i.e., both dimensions = are=20 free. float **distances; In this declaration only a pointer that is = capable=20 of keeping an address is defined. We keep an address in this = variable. This=20 address will be an address of an address of a floating point number. = We must=20 allocate spaces for each dimension and free them explicitly.
      /* =
      code for allocation */
      printf("Enter the number of cities:");
      scanf("%d",&no);
      distance =3D (float **)malloc(no * sizeof(float));
      for (i =3D 0; i < no; i++){
         printf("Enter the number of towns of city %d:",i);
         scanf("%d",&noTown);
         distance[i] =3D (float *)malloc(noTown * sizeof(float));
      }
        =20
      /* code for deallocation */
      for (i =3D 0; i < no; i++)
         free(distance[i]);
      free(distance);
  7. File Operations=20

    So far, we all read data from the standard input and write data on = the=20 standard output. These operations are automatically defined for a = program by=20 the operating system. Moreover, your program can also access a file = that has=20 already connected to the program.

    There is a structure that contains information about the file = (location of=20 a buffer, current position in the buffer, read/write flags, etc.). We = have a=20 file pointer points to this structure. The declaration of a file is = given as=20 follows:

    FILE *id;

    The FILE * data type is defined in stdio.h. Before you access a = file, you=20 should connect to it by fopen function. You must specify the = filename=20 (with its path) and the mode of the operation in this function. Mode = can be=20 write(w), read(r), append(a), etc. For example if you open the file = with read=20 mode and try to write some data into it, you may have problem. The = following=20 example connects the file with name data.txt for the write operation. = If there=20 is some error, e.g. if a file with the specified name is not found, = fopen=20 function returns to NULL.

    FILE *fid;
    fid =3D fopen("data.txt","w");

    Some functions defined on the files are given as follows. You can = find=20 detailed information or more functions in the stdio.h library or any = reference=20 book. Note that before performing these operations, you must connect = the=20 corresponding file, i.e., you must open it.

    1. fprintf: to print the formatted data into a file which = has=20 already opened.
      fprintf(fid,"%dHello =
      world\n%f\t%s\n",12,data,str);
    2. fscanf: to read data from the opened file. =
      fscanf(fid,"%d%c",&myInt, &myChar);
    3. fgets: to read characters from stream into the string s. = It stops=20 when it reads either n-1 characters or a newline character, = whichever comes=20 first. On success, it returns the string pointed to s. On error or=20 end-of-file, it returns NULL.
      char *fgets(char *s, int n, FILE =
      *stream);
    4. fputs: It copies the null terminated string s to the = given output=20 stream. It does not append a newline character and the terminating = null=20 character is not copied. On success, it returns the last character = written.=20 On error, it returns EOF.=20
    5. EOF: It is a constant indicating that end-of-file has = been=20 reached on a file.

    We should break the connection between the file pointer and its = external=20 name, freeing the file pointer by using fclose function. =

    fclose(fid);
    • There are limitations on the number of files that may open in a = program.=20 So close them if they are no longer needed.=20
    • After the program is terminated, fclose is called automatically = for each=20 open file.=20
    • Do not try to close a file that was not opened. Otherwise you = may have=20 some problems.

    Example: In the following example, data entered by the user = is=20 written in a file called info.dat. Then this information (in info.dat) = is=20 read. For this purpose, write a function that reads and writes data = from/into=20 a file.


    #include <stdio.h>
    
    void writeIntoFile(char *filename){
       FILE *id;
       int n, i;
       double data;
       id =3D fopen(filename,"w");
       printf("Enter the number of data to be entered:");
       scanf("%d",&n);
       for (i =3D 0; i < n; i++){
          scanf("%lf",&data);
          fprintf(id,"%lf\n",&data);
       }
       fclose(id);
    }
    
    double *readFromFileIntoAnArray(char *filename, int *no){
       FILE *myFile =3D fopen(filename,"r");
       double *myData =3D NULL, temp;
       *no =3D 0;
       while (fscanf(myFile,"%lf",&temp) !=3D EOF){
          (*no)++;
          myData =3D (double *)realloc(myData,(*no) * sizeof(double));
          myData[(*no) - 1] =3D temp;
       }
       fclose(myFile);
       return myData;
    }
    
    int main(){
       double *data;
       int no, i;
       writeIntoFile("info.dat");
       data =3D readFromFileIntoAnArray("info.dat",&no);
       for (i =3D 0; i < no; i++)
          printf("%lf\n",data[i]);
       free(data);
      =20
       anykey();
       return 0;
    }
    

------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: image/jpeg Content-Transfer-Encoding: base64 Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/onlineCourseNotes/Figure1.JPG /9j/4AAQSkZJRgABAQEAkACQAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAIPAVEDASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3 ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm p6ipqrK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HQH3FAFM6LqH/C3l137P8A8S0aCbPz t6/67zw+3bnd93nOMe9ea618P/Emo3evR3XhK21bULuWc2uu3eq/JHE2dirBn5WUcDjAOOwr3eig Dzmy8M6yl/8ADKaSxKLotlNDqGZUPksbVYx0b5ssCPlzWv4d0TUbH4i+M9VubfZZal9h+yS71Pme XCVfgHIwTjkDPauvooA5P4Z6NqHh/wCHmkaVqlv9nvbdJBLFvV9uZGYcqSDwR0NdZWLrfi3QPDgx quq21vIfuwlt0rf7qDLH8BWE2reLfFIMei6edA09+P7R1JM3DD1jg7H3c/hQBr+JfFtp4e8m1jhe /wBXuuLTTrcgyzH1P91B3Y8DmoPCXhy501rzWNZkjn1/UmD3UkeSkSD7kMef4FH5nJNWfDvhHS/D fmzW6yXF/cc3N/dP5k85/wBpz29hge1b1ABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUU AFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABXO6z4F8N67P8AabvS4kvByLu2JhnB9d6YP5mu iooA4s+DtfsOdF8caoi/88tTijvVPtuIVx/31Qbj4j2HMlj4d1aMdoJ5bWRvwYOv612lFAHF/wDC XeKYf+Pv4e6io55tr63m6f8AAgaevju72jd4H8VBscgW8J/9q12NFAHHN46vSMReBvFDOTgB4IFH 5+acUg8UeLZ/+PbwDdKCeGutSgiH4hSxH5V2VFAHGH/hZF9/0LelRt/12upF/wDQF/nR/wAIRqd+ P+J74z1m7B4MVkUsoyPQiMbsf8Crs6KAMXRfCPh/w6S2laTbW8p+9Nt3St9ZGyx/E1tUUUAFFFFA BRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQB//2Q== ------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: text/css; charset="iso-8859-9" Content-Transfer-Encoding: quoted-printable Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/onlineCourseNotes/style.css H1 { FONT-FAMILY: verdana } H2 { FONT-FAMILY: verdana } H3 { FONT-FAMILY: verdana } H4 { FONT-FAMILY: verdana } H5 { FONT-FAMILY: verdana } H6 { FONT-FAMILY: verdana } H4 { MARGIN: 15px; FONT: bold 24px verdana; COLOR: red } P { FONT: 12px verdana; COLOR: black } OL.chapter_index LI { FONT: bold 12px verdana; COLOR: black } UL LI { MARGIN: 10px; FONT: 12px verdana; COLOR: black } OL.subsection LI { MARGIN: 5px; FONT: bold 20px verdana; COLOR: #5555ff } OL.subsection LI OL LI { FONT: 12px verdana; COLOR: black } OL.subsection LI UL LI { FONT: 12px verdana; COLOR: black } UL.subsection LI OL LI { FONT: 12px verdana; COLOR: black } UL.subsection LI UL LI { FONT: 12px verdana; COLOR: black } PRE P { FONT: bold 16px courier new } TABLE TD { PADDING-RIGHT: 8px; PADDING-LEFT: 8px; PADDING-BOTTOM: 4px; = PADDING-TOP: 4px } TABLE TH { PADDING-RIGHT: 8px; PADDING-LEFT: 8px; PADDING-BOTTOM: 4px; = PADDING-TOP: 4px } TABLE.bordered TD { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid } TABLE.bordered TH { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid } TABLE.centered TD { TEXT-ALIGN: center } TABLE.equation { =09 } A.topLink { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; COLOR: silver; BORDER-BOTTOM: silver 1px = solid } ------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: text/css; charset="iso-8859-9" Content-Transfer-Encoding: quoted-printable Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/style.css BODY { BACKGROUND-COLOR: #ffffff } BODY { FONT: 12px verdana } DIV { FONT: 12px verdana } A { FONT: 12px verdana } TABLE { FONT: 12px verdana } BUTTON { FONT: 12px verdana } INPUT { FONT: 12px verdana } .richCodeEditorContainer { FONT: bold 16px courier new } .richCodeEditorContainer P { FONT: bold 16px courier new } DIV.richCodeEditor { BORDER-RIGHT: #b0c4de 2px solid; BORDER-TOP: #b0c4de 2px solid; FONT: = bold 16px courier new; BORDER-LEFT: #b0c4de 2px solid; WIDTH: 3000px; = BORDER-BOTTOM: #b0c4de 2px solid } .lineNumbers { PADDING-RIGHT: 2px; PADDING-BOTTOM: 0px; FONT: bold 16px courier new; = COLOR: #888888; PADDING-TOP: 0px; TEXT-ALIGN: right } .lineNumbers P { PADDING-RIGHT: 2px; PADDING-BOTTOM: 0px; FONT: bold 16px courier new; = COLOR: #888888; PADDING-TOP: 0px; TEXT-ALIGN: right } A { COLOR: #4040f0; TEXT-DECORATION: none } A:hover { COLOR: red } TABLE.tabs TD { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: = 0px; FONT: bold 12px verdana; TEXT-TRANSFORM: uppercase; PADDING-TOP: = 0px; BORDER-COLLAPSE: collapse; TEXT-ALIGN: center } TABLE.tabs TH { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: = 0px; FONT: bold 12px verdana; TEXT-TRANSFORM: uppercase; PADDING-TOP: = 0px; BORDER-COLLAPSE: collapse; TEXT-ALIGN: center } TD.tab { BORDER-RIGHT: silver 2px solid; BORDER-TOP: silver 2px solid; = BORDER-LEFT: silver 2px solid; BORDER-BOTTOM: silver 2px solid } TD.chosen { BORDER-BOTTOM: white 2px solid; BACKGROUND-COLOR: white } TD.unchosen { BACKGROUND-COLOR: #ffffcc } #editorButtonsConst { LEFT: 0px; POSITION: relative; TOP: 0px } .errMsg { COLOR: red } .errMsgBig { FONT-SIZE: 33px; COLOR: red; FONT-FAMILY: verdana } .infMsg { COLOR: green } .codeColor { COLOR: black } .reserved { COLOR: blue } .error { BACKGROUND-COLOR: red } .preproc { COLOR: black; BACKGROUND-COLOR: #00ff00 } .preproc .firstOccurenceOfTheWord { COLOR: black; BACKGROUND-COLOR: #00ff00 } .string { COLOR: red } .string .firstOccurenceOfTheWord { COLOR: red } .character { COLOR: magenta } .character .firstOccurenceOfTheWord { COLOR: magenta } .comment { COLOR: green } .comment .firstOccurenceOfTheWord { COLOR: green } .firstOccurenceOfTheWord { COLOR: gray; FONT-STYLE: italic } .width100 { WIDTH: 100px } .width200 { WIDTH: 200px } P { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: = 0px; PADDING-TOP: 0px } TABLE { BORDER-COLLAPSE: collapse } TABLE.form { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; WIDTH: 500px; BORDER-BOTTOM: silver 1px = solid; BORDER-COLLAPSE: collapse } TABLE.form TR TD { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; PADDING-BOTTOM: 7px; = PADDING-TOP: 7px; BORDER-COLLAPSE: collapse } TABLE.form TR TH { BORDER-RIGHT: silver 1px solid; PADDING-RIGHT: 13px; BORDER-TOP: silver = 1px solid; PADDING-LEFT: 13px; PADDING-BOTTOM: 13px; BORDER-LEFT: silver = 1px solid; PADDING-TOP: 13px; BORDER-BOTTOM: silver 1px solid; = BORDER-COLLAPSE: collapse } TABLE.work { BACKGROUND-COLOR: #ccccff } TABLE.exam { BACKGROUND-COLOR: #ffbbbb } TABLE.staff { BACKGROUND-COLOR: #cccccc } TABLE.admin { BACKGROUND-COLOR: #aaaaaa } TABLE.files TR TD { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; PADDING-BOTTOM: 7px; = PADDING-TOP: 7px } TABLE.files TR TH { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; PADDING-BOTTOM: 7px; = PADDING-TOP: 7px } TABLE.files TR.odd TD { BACKGROUND-COLOR: #ddddff } TABLE.files TR.even TD { BACKGROUND-COLOR: #ffffcc } TABLE.bordered TD { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid } TABLE.bordered TH { BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; = BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid } TABLE.unbordered TD { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: = 0px } TABLE.unbordered TH { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: = 0px } TABLE.button_container TR TD { PADDING-BOTTOM: 20px } TABLE.richCodeEditorContainer { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: = 0px; BORDER-COLLAPSE: collapse } TABLE.richCodeEditorContainer TR TD { BORDER-RIGHT: 0px; PADDING-RIGHT: 0px; BORDER-TOP: 0px; PADDING-LEFT: = 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: 0px; PADDING-TOP: = 0px; BORDER-BOTTOM: 0px } .capitalized { TEXT-TRANSFORM: capitalize } OL.chapter_index LI { MARGIN-TOP: 10px } FIELDSET.narrow { PADDING-RIGHT: 20px; MARGIN-TOP: 20px; DISPLAY: block; PADDING-LEFT: = 20px; PADDING-BOTTOM: 20px; WIDTH: 450px; PADDING-TOP: 20px } LEGEND { FONT-WEIGHT: bold; COLOR: gray } FIELDSET FORM { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: = 0px; PADDING-TOP: 0px } FIELDSET TABLE TD { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; = PADDING-TOP: 5px } FIELDSET { -moz-border-radius: 8px; border-radius: 8px } ------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: text/css; charset="iso-8859-9" Content-Transfer-Encoding: 7bit Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/ie_fixes.css FIELDSET.narrow { } LEGEND { MARGIN-BOTTOM: 20px } ------=_NextPart_000_0000_01C877A8.678464C0 Content-Type: application/octet-stream Content-Transfer-Encoding: 7bit Content-Location: http://cmpe150-1.cmpe.boun.edu.tr/phpccompiler/RichCodeEditor/main.js /* This is the main js file. In order to use rich editing features of online compiler, this file must be included and RichCodeEditorPath variable must be given. Other files must not be included since this file includes them automatically */ function include(script_filename) { var html_doc = document.getElementsByTagName('head').item(0); var js = document.createElement('script'); js.setAttribute('language', 'javascript'); js.setAttribute('type', 'text/javascript'); js.setAttribute('src', script_filename); html_doc.appendChild(js); return false; } //var RichCodeEditorPath -> expected from outside include(RichCodeEditorPath+'/common.js'); include(RichCodeEditorPath+'/helpManager.js'); include(RichCodeEditorPath+'/RichCodeEditor.js'); include(RichCodeEditorPath+'/RichCodeEditorManager.js'); ------=_NextPart_000_0000_01C877A8.678464C0--