Home > Tag Archives: C

Tag Archives: C

July, 2011

  • 21 July

    Programming In C: Functions with Viewer Choice

    Using a Conditional inside a User-Defined Function If you want to give the viewer a choice of options, this can be handled either inside a user-defined function, or in the main( ) function. Let’s begin by handling viewer choice inside a user-defined function. In this example, a customer chooses how many books to order. The company uses this chart to ...

  • 5 July

    Programming In C: Built In & User Defined Functions

    There are several different types of functions in C. So far, we have used one type of function – the built-in C functions, like printf( ) and scanf( ). These functions are part of the C programming language. Another type is called a user-defined function. This is a function which the programmer creates and uses in a C program. We will learn ...

June, 2011

  • 21 June

    Programming In C: Character Type Library Functions

    Character Type Header File If you need to check what type of character the viewer typed, use ctype.h which is the character type header file. We write it like this: #include<ctype.h> Here is a list of character type library functions: isalpha  checks if the input is an alphabetical letter  isdigit  checks if the input is a number  isupper  checks if the input ...

  • 21 June

    Programming In C: More Library Functions – strcmp, stricmp, strcat, strstr

    strcmp: compare two strings You can compare the characters and spaces in a string using the strcmp function. For example, is “William Lambton” the same as “William Lamberton”? Using strcmp, the computer will compare each character and space, to see if they are identical. If the names are the same, the computer will return a value of 0. We can express this ...

  • 21 June

    Programming In C: Library Functions for Strings – strcpy, strlen

    C Library Functions for Strings C comes with libraries of special functions, that we can use in our programs. These functions are stored in the string header file, <string.h>, which we include at the beginning of our program: #include<string.h> Here is a list of string library functions: strcpy copies a string strlen calculates the length of a string strcmp compares ...

  • 21 June

    Programming In C: Declaring Strings & Gets and Puts Functions

    Declaring (Initializing) Strings As we learned in the lesson on Characters and Strings, a string is a character variable with more than one character. Strings can be abbreviations, words, phrases, sentences, or even paragraphs. To declare a string, use the char variable type, then specify how many characters are in the string. Add one to this number, because at the end of the ...

  • 21 June

    Programming In C: Using a Pointer to Change the Value of a Variable

    Declaring (Initializing) Pointers As we learned in the previous lesson, a pointer contains the address of a variable. Different types of variables have different types of pointers. For example, an integer variable will have an integer pointer; a float variable will have a float pointer. Pointers can be variables too. You can declare a pointer at the beginning of a program, ...

  • 16 June

    Programming in C: Information Storage, Variable Addresses and Viewer Input

    Information Storage We know that computers store information in memory. Each byte of information has a specific location in the memory area. This location is called the address. Whenever you use a variable, the value of the variable is stored in a specific address. This is why we used the ampersand & with the scanf function, like this: scanf(“%d”, &year); ...

  • 16 June

    Computer Number Systems

    Bits and Bytes Computers store information in bits, which are labeled 0 (empty) or 1 (full). A set of 8 bits is called a byte, like this: 1010 0010 Each byte has an address, which is labeled with a hexadecimal number, like this: C7.

  • 14 June

    Programming In C: Counting Array Elements & Sizes

    Size of an Array How much space in memory does an array occupy? We can calculate this by using a special operator: sizeof. This operator calculates how many bytes of memory are occupied by an array. For example, here is an array: numbers[3] = { 8, 29, 63 }; Using sizeof, I can write: printf(“The numbers array occupies %d bytes of memory.”, sizeof ...

  • 14 June

    Programming In C: Array of Arrays

    Array of Arrays If you have several arrays, you can combine them into an array of arrays. This is a large array that consists of two or more small arrays. For example, let’s say I have two arrays, each with three elements: first[3] = { 11, 17, 23 }; second[3] = { 46, 68, 82 }; Each array has 3 elements. Now ...

  • 14 June

    Programming In C: Arrays and Loops

    Arrays and Loops If you need to perform a function on each element in an array, then use a for loop. Set the counter at 0, so that the loop will start with the array element in index 0, and then loop through each element of the array: for(i = 0; i < number of elements; i++) In this case, the number ...

  • 14 June

    Programming In C: Initializing Arrays & Isolating Elements

    Initializing an Array An array is a set (group) of numbers. (C does not allow for arrays of characters or strings. Use Perl for these.) Here is a sample array: int years[3] = { 1800, 1900, 2000 }; This array is a set (group) of three years: 1800, 1900, and 2000. Each of these is called an element. I put the number ...

  • 7 June

    Programming In C: Infinite and Nested Loops

    Infinite Loops If you want the viewer to decide when to exit a loop, use an infinite for loop. The infinite for loop sets no requirements inside the for statement, like this: for( ; ; ) Many people shop online, using the internet. Here is a program to help you keep track of how much money you’ve spent. In this program, ...

  • 7 June

    Programming In C: For Loops, Numbers and Pictures

    Listing numbers We can use for loops to perform various automated tasks. For example, if you want to list a set of numbers on the screen, simply use a for loop and the %d format specifier. This is post #12 of 25 in the series “Programming In C” The following series of tutorials are designed for people with little or no ...

  • 7 June

    Programming In C: Introducing For Loops

    A for loop repeats a function for a specific number of times. Increment and decrement For loops use increment and decrement operators. increment means to loop again, counting up (1, 2, 3, 4, …) The symbol for increment is++ decrement means to loop again, counting down (… 4, 3, 2, 1) The symbol for decrement is — This is post #11 of 25 in ...

  • 7 June

    Programming In C: While Loops

    While Loops A while loop repeats a function until a condition is met. Simple while loops Have you ever kept repeating a question until someone gives you the correct answer? (Teachers do this all the time.) This is called a while loop. For example, let’s ask the viewer what year C was developed. The correct answer is 1971, so if the viewer ...

  • 7 June

    Programming In C: Multiple Conditions

    Switch (Multiple Conditions) A switch is a function that handles multiple conditions and gives a different response to each condition. It is a very complex type of conditional. Switch If you ask a question that could have several different answers, and you want to give a different response to each answer, then you must use a switch. This is post #9 of ...

  • 7 June

    Programming In C: Special Conditional Operators

    Special Operators (Logical and Conditional) An operator is a function that performs a mathematical calculation, such as addition, or a logical calculation, such as or. Logical Operators In complex conditionals, we use logical operators to test whether multiple conditions are true or false. Here is a list of logical operators: &&  || !   and  or not   tests if two conditions ...

  • 7 June

    Programming In C: Simple and Nested Conditionals

    Simple Conditional, Nested Conditional A conditional is an if … else statement. For example: If you study, then you will succeed, or else you will fail.    This example has three parts: the condition: If you study, if the condition is met: then you will succeed, if the condition is not met: or else you will fail. Notice that there are different outcomes, whether ...

Like every other website, this site uses cookies to analyze our traffic. Cookies may also be utilized by our advertisers and partners. By using this website you agree to the use of said cookies. More Information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings, continuing to navigate past this message, or you click "Accept" below then you are consenting to the use of cookies on the Rapid Purple website.