STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 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.
Copyright  Hannu Laine C++-programming Part 5 Strings.
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
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.
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:
Pointers and Strings. Introduction Pointers –Powerful, but difficult to master –Simulate call-by-reference –Close relationship with arrays and strings.
Memory Arrangement Memory is arrange in a sequence of addressable units (usually bytes) –sizeof( ) return the number of units it takes to store a type.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
N-1 University of Washington Computer Programming I Lecture 19: Strings © 2000 UW CSE.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
C++ for Engineers and Scientists Third Edition
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
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.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
CHAPTER 8 CHARACTER AND STRINGS
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Two-week ISTE workshop on Effective teaching/learning of computer programming Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
 2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 6 Array and String.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
(9-1) Strings I H&K Chapter 8 Instructor - Andrew S. O’Fallon CptS 121 (October 19, 2015) Washington State University.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Programming Fundamentals. Today’s Lecture Multidimensional Arrays Arrays as Class Member Data Arrays of Objects C-Strings.
String operations. About strings To handle strings more easily, we need to include a library> #include To see what the library allows us to do, look here:
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Characters and Strings
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
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.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
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.
19-Feb-02 Sudeshna Sarkar, CSE, IIT Kharagpur1 Arrays, Pointers, Strings Lecture 18 19/2/2002.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Strings CSCI 112: Programming in C.
Chapter 4 C Program Control Part I
A First Book of ANSI C Fourth Edition
L7 – Assembler Directives
Lecture 8b: Strings BJ Furman 15OCT2012.
Pointers and Pointer-Based Strings
Week 9 – Lesson 1 Arrays – Character Strings
4.1 Strings ASCII & Processing Strings with the Functions
C++ Programming Lecture 20 Strings
cout << str1;  pear
Presentation transcript:

STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS

The char Data Type Variables of type char take up typically one byte in memory and are used to store printable and non-printable characters. The ASCII code is used to associate each character with an integer For example the ASCII code associates the character ‘m’ with the integer 109. Internally, C treats character variables as integers.

ASCII CHARACTER SET

WHAT ARE STRINGS In C strings are represented as array of characters Strings ie character arrays are always terminated by a null character(\0) at the end by default Note \0 is used to identify the end of the string ASCII value of \0 is 0

Representation of strings in memory The fig shows how the string “college” is represented in the computers memory

Declaring strings

Reading string inputs Here the string is read with the help of a loop control character by character. This method is very rarely used The declaration char code[20] ; must be done earlier in the program

Reading string inputs Here a single word is read. In case of multiple words separated by spaces only the first word is read. This method is used when we are sure that the inputs will not contain multiple words separated by spaces Note: While scanning the ‘&’ symbol is not used as in other cases

Reading string inputs The gets( ) is an inbuilt function available with library. This function can read multiple words which are separated by spaces

Printing/displaying the strings

PROBLEM 1: Write a program to store the name of a student and then display the same

PROBLEM 2: Write a program to find the length of the name(without using string function)

PROBLEM 3: Write a program to check whether two strings are equal (without using string functions)

PROBLEM 4: Write a program to count the number of vowels in a string

PROBLEM 4: Write a program to count the number of words in a string

Lot of string handling functions are available in the header file So whenever we want to make use of these inbuilt library functions in our program then we must include the string.h file

FUNCTIONS IN STRING.H

SOME POPULAR ONES

Examples of String Functions Here are some examples of string functions in action: char s1[]="big sky country"; char s2[]="blue moon"; char s3[]="then falls Caesar ";

Write a program to compare two strings and to concatenate them if they are unequal

PROBLEM 5: Write a program to check whether a given string is palindrome or not

PROBLEM 2: Write a program to sort a list of names in ascending order