In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.

Slides:



Advertisements
Similar presentations
Problem Solving & Program Design in C
Advertisements

Unit 10 Miscellaneous Advanced Topics Introduction to C Programming.
 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Programming Languages and Paradigms The C Programming Language.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
Lecture 20 Arrays and Strings
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Chapter Fourteen Strings Revisited. Strings A string is an array of characters A string is a pointer to a sequence of characters A string is a complete.
Searching and Sorting an Array 4 Searching and sorting are two fundamental algorithms often implemented with arrays –Search an array to determine the location.
C Strings. The char Data Type for Storing Characters The char data type can is used to declare a variable that can hold a single character. Examples:
Chapter 10.
1 CSSE 332 Preprocessor, Array and Strings. 2 External library files libname.a or libname.so Special functionality is provided in the form of external.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
String What it is Why it’s useful library routines for handling strings how to input a string from the keyboard.
C-strings Array with base type char One character per indexed variable
C Arrays and Pointers In Java, pointers are easy to deal with –In fact, there is little that can go wrong in Java since pointer access is done for you.
Strings. Sentences in English are implemented as strings in the C language. Computations involving strings are very common. E.g. – Is string_1 the same.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Arrays and Strings Gabriel Hugh Elkaim Spring 2013.
Data Structure and C Part-6. Naming a Function Any valid variable-name can be given to the user-defined function. The main program itself is considered.
Introduction to C programming
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
Chapter 8 Arrays and Strings
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
COP 3530 Data Structures & Algorithms Discussion Session 3.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Structured Programming Approach Module VIII - Additional C Data Types Arrays Prof: Muhammed Salman Shamsi.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
String Array (Multidimensional Arrays) 1. A string array is a multidimensional array of strings. It is declared in the following syntax: char variable_name[No_of_strings][size_of_each_string];
Programming in C Arrays, Structs and Strings. 7/28/092 Arrays An array is a collection of individual data elements that is:An array is a collection of.
UniMAP SEM I - 09/10EKT 120 Computer Programming1 Lecture 8 – Arrays (2) & Strings.
C vs. C++ I/O Declaration Placement Strings Minor syntax differences (ala enum)
Arrays.
1. Define an array 1 Create reference arrays of objects in Java program 2 Initialize elements of arrays 3 Pass array to methods 4 Return array to methods.
Strings, Slide Fundamental Programming Strings.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
1 Pointers: Parameter Passing and Return. 2 Passing Pointers to a Function Pointers are often passed to a function as arguments  Allows data items within.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
 Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
Strings. String Literals String literals are enclosed in double quotes: "Put a disk in drive A, then press any key to continue\n“ A string literal may.
1 C Basics. 2 The C Language Spirit Made by professional programmers for professional programmers Very flexible, very efficient, very liberal Does not.
UNIT - 3 ARRAYS AND STRINGS. Array An Array is a collection of similar data items, that are stored under a common name. Types –One-Dimensional array –Two-Dimensional.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Lecture-5 Arrays.
Module 2 Arrays and strings – example programs.
ARRAYS An array is a sequence of data item of homogeneous value(same type). Arrays are of two types: 1. One-dimensional arrays 2. Multi-Dimensional arrays.
Arrays in C.
Programming Languages and Paradigms
Arrays, For loop While loop Do while loop
Strings A collection of characters taken as a set:
CPS120: Introduction to Computer Science
CHAPTER 2 Arrays and Vectors.
CHAPTER 2 Arrays and Vectors.
Presentation transcript:

In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students. This can be done by creating 100 variable individually but, this process is rather tedious and impracticable. These type of problem can be handled in C programming using arrays. Arrays

An array is a sequence of data item of homogeneous value(same type). Arrays are of two types: 1.One-dimensional arrays 2.Multidimensional arrays Arrays

Declaration of One-Dimensional Array data_type array_name[array_size]; For example: int age[5]; Here, the name of array is age.The size of array is 5,i.e., there are 5 items(elements) of array age. All element in an array are of the same type (int, in this case). Note that, the first element is numbered 0 and so on.

Arrays can be initialized at declaration time in this source code as: int age[5]={2,4,34,3,4};

It is not necessary to define the size of arrays during initialization. int age[]={2,4,34,3,4}; In this case, the compiler determines the size of array by calculating the number of elements of an array

Arrays with multi-dimension data_type array_name[array_size][array_size]…; C programming language allows programmer to create arrays of arrays known as multidimensional arrays. For example: float a[2][6]; Here, a is an array of two dimension, which is an example of multidimensional array.

In C, multidimensional arrays can be initialized in different number of ways: int c[2][3]={{1,3,0}, {-1,5,9}}; OR int c[][3]={{1,3,0}, {-1,5,9}}; OR int c[2][3]={1,3,0,-1,5,9}; Initialization of Multidimensional Arrays

Strings are declared in C in similar manner as arrays. Only difference is that, strings are of char type. char s[5]; Attention ! - Strings can also be multi-dimensioned but we will discuss it later… Strings Syntax >> char array_name[element_amount];

#include //They included by string.h library -strrev -strlen -strcpy -strcat -strcmp Generally Used String Functions

strrev strrev(variable_name) -Reflects the string…

strlen strlen(variable_name) - Returns the number of elements in string…

strcpy strcpy(variable1_name,variable2_name) - Makes a copy of a string…

strcat strcat(variable1_name,variable2_name) - Appends a string to the end of another string…

strcmp strcmp(variable1_name,variable2_name) - Compares two strings alphabetically…