Example: ? str1 str2 _ void salin(char sasaran[], char sumber[]);

Slides:



Advertisements
Similar presentations
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Advertisements

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.
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.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
1 Introduction to Computing: Lecture 16 Character Strings Dr. Bekir KARLIK Yasar University Department of Computer Engineering
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
1 Introduction to Computing Lecture 11 Character Strings Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering
N-1 University of Washington Computer Programming I Lecture 19: Strings © 2000 UW CSE.
To remind us We finished the last day by introducing If statements Their structure was:::::::::
Strings A special kind of array is an array of characters ending in the null character \0 called string arrays A string is declared as an array of characters.
1 CSE1301 Computer Programming: Lecture 19 Character Strings.
Tutorial #8 Summer strings #include int main() { char str1[] = {‘h’,’e’,’l’,’l’,’o’}; char str[] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; char p[] = ”hello”;
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.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 13 Strings (Continued)
String functions+ string I.Mona Alshehri. String Functions: Header file:#include Function: Int strlen(char s[n]) Description Calculates the length of.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
13. 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.
Principles of Programming Chapter 8: Character & String  In this chapter, you’ll learn about;  Fundamentals of Strings and Characters  The difference.
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.
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.
CSE 251 Dr. Charles B. Owen Programming in C1 Strings and File I/O.
13. 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.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
MULTI-DIMENSION ARRAY STRING Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
String in C++. 2 Using Strings in C++ Programs String library or provides functions to: - manipulate strings - compare strings - search strings ASCII.
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
Chapter 8 “Character Arrays and Strings” Prepared by: Prof. Ajay M. Patel CE, IDS, NU.
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
C Characters and Strings
Fundamentals of Characters and Strings
DEPARTMENT OF COMPUTER SCIENCE & APPLICATION
Lecture 8 String 1. Concept of strings String and pointers
CSE 303 Lecture 14 Strings in C
Strings A string is a sequence of characters treated as a group
Computer Science 210 Computer Organization
Arrays in C.
מחרוזות קרן כליף.
Computer Science 210 Computer Organization
CS111 Computer Programming
C Stuff CS 2308.
CSI 121 Structured Programming Language Lecture 21 Character Strings
Engr 0012 (04-1) LecNotes
INC 161 , CPE 100 Computer Programming
Character & String Knowledge
Strings A collection of characters taken as a set:
Chapter 9 One-Dimensional Arrays
Lecture 11 Strings.
String in C++.
CprE 185: Intro to Problem Solving (using C)
EECE.2160 ECE Application Programming
Strings What is a string? It is an array of characters terminated with
Chapter 8 Character Arrays and Strings
String manipulation string.h library
Introduction to Computer Organization & Systems
Strings Adapted from Dr. Mary Eberlein, UT Austin.
C++ Programming Lecture 20 Strings
Strings in C Array of characters is called a string.
Character Arrays char string1[] = “first”;
Strings #include <stdio.h>
Characters and Strings Functions
Strings Adapted from Dr. Mary Eberlein, UT Austin.
C Characters and Strings
Introduction to Problem Solving and Programming
Presentation transcript:

Example: ? str1 str2 _ void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; ? str1 str2 _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 Selamat _ void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 Selamat _ void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 1 i Selamat _

Example : Until … 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber Until … sasaran 2 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 7 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 7 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 7 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 ? str2 sumber sasaran 7 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 sumber sasaran 7 i void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 sumber sasaran 7 i Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 Selamat _ void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 Selamat _

Example : 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 Selamat _ void salin(char sasaran[], char sumber[]); int main() { char str1[8], str2[8]; scanf("%s", str1); salin(str2, str1); printf("Salinan: %s\n", str2); } void salin(char sasaran[ ], char sumber[ ]) { int i = 0; while (sumber[i] != '\0') { sasaran[i] = sumber[i]; i++; sasaran[i] = '\0'; 'S' 'e' 'l' 'a' 'm' 't' '\0' str1 str2 Selamat _

Character Manipulation Function Special function was provided in standard library C for manipulating character. Refer to Jadual 12.1 (page 333) in Pengaturcaraan C

Example: Input one word #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); Input one word

Example : Copy every character #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); Copy every character

Example: End of string character? #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); End of string character?

Example : Is this small alphabet? #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); Is this small alphabet?

Example: If yes, assign capital letter for #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); If yes, assign capital letter for that character into array str2

Example: If not, assign that character into array str2 #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); If not, assign that character into array str2

Example: Next index #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); Next index

Example: Don’t forget null character!!! #include <stdio.h> #include <ctype.h> int main() { char str1[8], str2[8]; int x = 0; printf("Masukkan satu perkataan: "); scanf("%s", str1); while (str1[x] != '\0') { if (islower(str1[x])) str2[x] = toupper(str1[x]); else str2[x] = str1[x]; x++; } str2[x] = '\0'; printf("%s dalam huruf besar: %s\n", str1, str2); Don’t forget null character!!!

getchar() and putchar() getchar() dan putchar() can be used for input and output character

Example : Read character by character into an array: #include <stdio.h> #define MAKS 8 int main() { char str[MAKS]; int x = 0; do { str[x] = getchar(); x++; } while (x < MAKS && str[x-1] != '\n'); str[x-1] = '\0'; x = 0; while (str[x] != '\0') { putchar(str[x]); } Read character by character into an array:

Example: Read next character #include <stdio.h> #define MAKS 8 int main() { char str[MAKS]; int x = 0; do { str[x] = getchar(); x++; } while (x < MAKS && str[x-1] != '\n'); str[x-1] = '\0'; x = 0; while (str[x] != '\0') { putchar(str[x]); } Read next character

Example: #include <stdio.h> #define MAKS 8 int main() { char str[MAKS]; int x = 0; do { str[x] = getchar(); x++; } while (x < MAKS && str[x-1] != '\n'); str[x-1] = '\0'; x = 0; while (str[x] != '\0') { putchar(str[x]); } Loop until there are no more items in array and before users pushing “enter”

Example: Don’t forget to insert null character into an array #include <stdio.h> #define MAKS 8 int main() { char str[MAKS]; int x = 0; do { str[x] = getchar(); x++; } while (x < MAKS && str[x-1] != '\n'); str[x-1] = '\0'; x = 0; while (str[x] != '\0') { putchar(str[x]); } Don’t forget to insert null character into an array

Example: Display an output for character by character inside an array #include <stdio.h> #define MAKS 8 int main() { char str[MAKS]; int x = 0; do { str[x] = getchar(); x++; } while (x < MAKS && str[x-1] != '\n'); str[x-1] = '\0'; x = 0; while (str[x] != '\0') { putchar(str[x]); } Display an output for character by character inside an array

gets() and puts() These functions gets() dan puts() can be used for input and output string

Example: Read two strings #include <stdio.h> int main() { char str1[5], str2[11]; int x, y; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); x = 0; while (str2[x] != '\0') x++; y = 0; while (str1[y] != '\0') { str2[x] = str1[y]; y++; } str2[x] = '\0'; printf("Hasil selepas cantuman: "); puts(str2); Read two strings

Example: Find index for null character in str2 #include <stdio.h> int main() { char str1[5], str2[11]; int x, y; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); x = 0; while (str2[x] != '\0') x++; y = 0; while (str1[y] != '\0') { str2[x] = str1[y]; y++; } str2[x] = '\0'; printf("Hasil selepas cantuman: "); puts(str2); Find index for null character in str2

Example: Insert every character in Str1 at the end of string in str2 #include <stdio.h> int main() { char str1[5], str2[11]; int x, y; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); x = 0; while (str2[x] != '\0') x++; y = 0; while (str1[y] != '\0') { str2[x] = str1[y]; y++; } str2[x] = '\0'; printf("Hasil selepas cantuman: "); puts(str2); Insert every character in Str1 at the end of string in str2

Example: Don’t forget null character #include <stdio.h> int main() { char str1[5], str2[11]; int x, y; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); x = 0; while (str2[x] != '\0') x++; y = 0; while (str1[y] != '\0') { str2[x] = str1[y]; y++; } str2[x] = '\0'; printf("Hasil selepas cantuman: "); puts(str2); Don’t forget null character

String manipulation functions String manipulation also provided with C. Such as : - strcpy() strlen() strcat() strcmp()

strcpy() strcpy() copies the contents of one string to another string. Prototype: char *strcpy(char sasaran[], char sumber[]);

Example: ? #include <stdio.h> asal int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } ? asal ? salinan _

Example: ? #include <stdio.h> asal int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } ? asal ? salinan Masukkan rentetan: _

Example: #include <stdio.h> int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } 'k' 'u' 'r' 's' '\0' ? asal ? salinan Masukkan rentetan: kursus _

Example: #include <stdio.h> int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } 'k' 'u' 'r' 's' '\0' ? asal 'k' 'u' 'r' 's' '\0' ? salinan Masukkan rentetan: kursus _

Example: #include <stdio.h> int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } 'k' 'u' 'r' 's' '\0' ? asal 'k' 'u' 'r' 's' '\0' ? salinan Masukkan rentetan: kursus Salinan: _

Example: #include <stdio.h> int main() { char asal[8], salinan[8]; printf("Masukkan rentetan: "); gets(asal); strcpy(salinan, asal); printf("Salinan: "); puts(salinan); } 'k' 'u' 'r' 's' '\0' ? asal 'k' 'u' 'r' 's' '\0' ? salinan Masukkan rentetan: kursus Salinan: kursus_

strlen() strlen() is a function returns the length of string. If the string is empty, it returns zero. Prototype: int strcpy(char rentetan[]);

Example : ? str1 ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else printf(“rentetan sama panjang\n"); } ? str1 ? str2 _

Example: 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola _

Example: 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola _

Example : 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 4 6 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola _

Example: 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola _

Example: 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola panjang rentetan 1 < rentetan 2 _

Example: 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strlen(str1) > strlen(str2)) printf(“panjang rentetan 1 > rentetan 2\n"); else if (strlen(str1) < strlen(str2)) printf(“panjang rentetan 1 < rentetan 2\n"); else printf(“rentetan sama panjang\n"); } 'b' 'o' 'l' 'a' '\0' ? str1 'b' 'e' 'o' 'l' 'a' '\0' ? str2 Masukkan rentetan 1: bola Masukkan rentetan 2: bebola panjang rentetan 1 < rentetan 2 _

strcat() strcat() append first string into the end of a second string Prototype : char *strcat(char s1[], char s2[]);

#include <stdio.h> int main() { char str1[5], str2[11]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); strcat(str2, " "); strcat(str2, str1); printf("Hasil selepas cantuman: "); puts(str2); } ? str2 ? str1 _

#include <stdio.h> int main() { char str1[5], str2[11]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); strcat(str2, "/"); strcat(str2, str1); printf("Hasil selepas cantuman: "); puts(str2); } '3' '1' '/' '0' '8' '\0' ? str2 '1' '9' '5' '7' '\0' str1 Masukkan rentetan 1: 1957 Masukkan rentetan 2: 31/08 _

#include <stdio.h> int main() { char str1[5], str2[11]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); strcat(str2, "/"); strcat(str2, str1); printf("Hasil selepas cantuman: "); puts(str2); } '3' '1' '/' '0' '8' '\0' ? str2 '1' '9' '5' '7' '\0' str1 Masukkan rentetan 1: 1957 Masukkan rentetan 2: 31/08 _

#include <stdio.h> int main() { char str1[5], str2[11]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); strcat(str2, "/"); strcat(str2, str1); printf("Hasil selepas cantuman: "); puts(str2); } '3' '1' '/' '0' '8' '9' str2 '5' '7' '\0' '1' '9' '5' '7' '\0' str1 Masukkan rentetan 1: 1957 Masukkan rentetan 2: 31/08 _

#include <stdio.h> int main() { char str1[5], str2[11]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); strcat(str2, "/"); strcat(str2, str1); printf("Hasil selepas cantuman: "); puts(str2); } '3' '1' '/' '0' '8' '9' str2 '5' '7' '\0' '1' '9' '5' '7' '\0' str1 Masukkan rentetan 1: 1957 Masukkan rentetan 2: 31/08 Hasil selepas cantuman: 31/08/1957_

strcmp() strcmp() compares two string until unequal characters are found or until the end of the string is reached. Prototype: int strcmp(char s1[], char s2[]); Return value strcmp(): If s1 < s2, so strcmp(s1, s2) < 0 If s1 > s2, so strcmp(s1, s2) > 0 If s1 equal to s2, so strcmp(s1, s2) == 0

Example: ? str1 ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } ? str1 ? str2 _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara rentetan 1 > rentetan 2 _

Example : 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 #include <stdio.h> int main() { char str1[8], str2[8]; printf("Masukkan rentetan 1: "); gets(str1); printf("Masukkan rentetan 2: "); gets(str2); if (strcmp(str1, str2) < 0) printf("rentetan 1 < rentetan 2\n"); else if (strcmp(str1, str2) > 0) printf("rentetan 1 > rentetan 2\n"); else printf("rentetan 1 bersamaan rentetan 2\n"); } 'W' 'i' 'r' 'a' '\0' ? str1 'I' 's' 'w' 'a' 'r' '\0' ? str2 Masukkan rentetan 1: Wira Masukkan rentetan 2: Iswara rentetan 1 > rentetan 2 _