INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Advertisements

1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
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.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
N-1 University of Washington Computer Programming I Lecture 19: Strings © 2000 UW CSE.
C Programming Strings. Array of characters – most common type of array in C  Let’s make them easier for use Denote the end of array using a special 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.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
CPT: Strings/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss strings and their relationship.
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’};
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Slides from Shane Griffith (TA and guest instructor in Fall 2008) CprE 185: Intro to Problem Solving.
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.
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
MULTI-DIMENSION ARRAY STRING Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
מערכים (arrays) 02 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 16 Department.
Computer Organization and Design Pointers, Arrays and Strings in C
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
INC 161 , CPE 100 Computer Programming
Fundamentals of Characters and Strings
INC 161 , CPE 100 Computer Programming
DEPARTMENT OF COMPUTER SCIENCE & APPLICATION
Lecture 8 String 1. Concept of strings String and pointers
Programming Languages and Paradigms
CSE 303 Lecture 14 Strings in C
Programming Paradigms
Module 2 Arrays and strings – example programs.
Computer science C programming language Lesson 5
Strings A string is a sequence of characters treated as a group
Arrays in C.
Programming Languages and Paradigms
Character Strings Lesson Outline
Programming and Data Structure
CS111 Computer Programming
C Stuff CS 2308.
Strings.
CSI 121 Structured Programming Language Lecture 21 Character Strings
CSE1320 Strings Dr. Sajib Datta
Engr 0012 (04-1) LecNotes
Chapter 9 One-Dimensional Arrays
C Characters and Strings – Review Lab assignments
Lecture 11 Strings.
String What it is Why it’s useful
CprE 185: Intro to Problem Solving (using C)
Strings Dr. Soha S. Zaghloul updated by Rasha ALEidan
EECE.2160 ECE Application Programming
Strings What is a string? It is an array of characters terminated with
Chapter 8 Character Arrays and Strings
CPS120: Introduction to Computer Science
Example: ? str1 str2 _ void salin(char sasaran[], char sumber[]);
String manipulation string.h library
INC 161 , CPE 100 Computer Programming
C++ Programming Lecture 20 Strings
Lecture 19: Working with strings
Character Arrays char string1[] = “first”;
Strings #include <stdio.h>
Programming Languages and Paradigms
Characters and Strings Functions
CS31 Discussion 1H Fall18: week 6
Library in c++ ( as cmath , iostream , …… etc.)
C Characters and Strings
Introduction to Problem Solving and Programming
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 7

String char stores 1 letter Word, sentence consists of several letters How to store words, sentences? Answer: Array of char (called string)

Char Constant and String Constant String constant “Hello” Processing string is like processing an array (do it one-by-one)

char a[10] = “Hello” ‘H’ ‘e’ ‘l’ ‘l’ ‘o’ ‘\0’ Don’t care what it stores End Character

Example 1 Note that no & #include <stdio.h> main() { char i = ‘Q’; char a[10]; scanf(“%s”, a); printf(“%s”, a); printf(“\n”); printf(“%c %c”, i, a[0]); }

Task 1 Write a flowchart/program that receives 1 string from the keyboard and print out the number of characters in that string. Example Hello world = 11 characters INC24 = 5 characters Hint: Loop until you find the terminate character.

string.h A library for string processing String length strlen() String compare strcmp() String copy strcpy() String concatenate strcat()

Example 2 Include string.h #include <stdio.h> main() { char s1[10]="ABCD", s2[10]="ABCD", s3[10]="abcd"; int a,b,c,n; a = strcmp(s1, s2); b = strcmp(s1, s3); c = strcmp(s3, s1); strcpy(s1, s3); strcpy(s1, "1234"); strcat(s1, "Hello"); n = strlen(s1); }

Example 3 #include <stdio.h> main() { char list[3][10] = {“John”,”Doe”,”Peter”}; printf(“%s”,list[0]); printf(“%s”,list[1]); printf(“%s”,list[2]); }

Task 2 From the list above, write a program that receives char list[3][10] = {“John”,”Doe”,”Peter”}; From the list above, write a program that receives a string from the keyboard and search whether the string is the name on the list. Print out “Yes” or “No”. Hint: Compare one-by-one name Use list[0] list[1] list[2] for each string.