Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Lectures on Busy Bee Workshop 1
Busy Bee Workshop – Session VIBusy Bee Workshop – Session VI
This session Outline
String
S...
Lectures on Busy Bee Workshop 2
String in CString in C
Sequence of characters is called string.
In C, a string constant is...
Lectures on Busy Bee Workshop 3
String in C - ImplementationString in C - Implementation
• C implements the stringstring d...
Lectures on Busy Bee Workshop 4
String in C – Memory StorageString in C – Memory Storage
• The string is always ended with...
Lectures on Busy Bee Workshop 5
String in C – Arrays of StringsString in C – Arrays of Strings
• An array of strings is a ...
Lectures on Busy Bee Workshop 6
String in C – Character vs. StringString in C – Character vs. String
Lectures on Busy Bee Workshop 7
String in C – Input/OutputString in C – Input/Output
• The placeholder %s%s is used to rep...
Lectures on Busy Bee Workshop 8
String in C – Right and Left Justification of StringsString in C – Right and Left Justific...
Lectures on Busy Bee Workshop 9
String in C – Example programString in C – Example program
Lectures on Busy Bee Workshop 10
String in C – Library FunctionsString in C – Library Functions
• The string can not be co...
Lectures on Busy Bee Workshop 11
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
s...
Lectures on Busy Bee Workshop 12
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
S...
Lectures on Busy Bee Workshop 13
String in C – Library FunctionsString in C – Library Functions
Function Purpose Example
S...
Lectures on Busy Bee Workshop 14
String in C – Example program (Library Function)String in C – Example program (Library Fu...
String c
String c
Nächste SlideShare
Wird geladen in …5
×

String c

C PROGRAMMING LANGUAGE

  • Als Erste(r) kommentieren

String c

  1. 1. Lectures on Busy Bee Workshop 1 Busy Bee Workshop – Session VIBusy Bee Workshop – Session VI This session Outline String String Manipulation Functions String Programs
  2. 2. Lectures on Busy Bee Workshop 2 String in CString in C Sequence of characters is called string. In C, a string constant is a sequence of characters enclosed in double quotes. Examples: “C Programming” “SVN College” “3/390 Nehru Street” “45”
  3. 3. Lectures on Busy Bee Workshop 3 String in C - ImplementationString in C - Implementation • C implements the stringstring data structure using arrays of type char. • We have already used the string extensively. – printf(“This program is terminated!n”); – #define ERR_Message “Error!!” • Since stringstring is an array, the declaration of a string is the same as declaring a char array. – char string_var[30]; – char string_var[20] = “Initial value”;
  4. 4. Lectures on Busy Bee Workshop 4 String in C – Memory StorageString in C – Memory Storage • The string is always ended with a nullnull charactercharacter ‘0’‘0’. • The characters after the null character are ignored. • e.g., char str[20] = “Initial value”; n i t i a l v a l u e ? ? …I 00 [0] [13]
  5. 5. Lectures on Busy Bee Workshop 5 String in C – Arrays of StringsString in C – Arrays of Strings • An array of strings is a two-dimensional array of characters in which each row is one string. – char names[People][Length]; – char names[10][25]; – char month[5][10] = {“January”, “February”, “March”, “April”, “May”};
  6. 6. Lectures on Busy Bee Workshop 6 String in C – Character vs. StringString in C – Character vs. String
  7. 7. Lectures on Busy Bee Workshop 7 String in C – Input/OutputString in C – Input/Output • The placeholder %s%s is used to represent string arguments in printf and scanf. • Example: char message1[12] = "Hello world"; printf(“%s”,message1); message1: char message2[12]; scanf(“%s”,message2); // type "Hello" as input message2: H e l l o w o r l d 0 H e l l o 0 ? ? ? ? ? ?
  8. 8. Lectures on Busy Bee Workshop 8 String in C – Right and Left Justification of StringsString in C – Right and Left Justification of Strings • The string can be right-justified by placing a positive number in the placeholder. – printf(“%8s%8s”, str); • The string can be left-justified by placing a negative number in the placeholder. – Printf(“%-8s%-8s”, str);
  9. 9. Lectures on Busy Bee Workshop 9 String in C – Example programString in C – Example program
  10. 10. Lectures on Busy Bee Workshop 10 String in C – Library FunctionsString in C – Library Functions • The string can not be copied by the assignment operator ‘=’. – e..g, “str = “Test String”” is not valid. • C provides string manipulating functions in the “string.h” library. – The list of these functions can be found in the next slide.
  11. 11. Lectures on Busy Bee Workshop 11 String in C – Library FunctionsString in C – Library Functions Function Purpose Example strcpy Makes a copy of a string strcpy(s1, “Hi”); strcat Appends a string to the end of another string strcat(s1, “more”); strcmp Compare two strings alphabetically strcmp(s1, “Hu”); strlen Returns the number of characters in a string strlen(“Hi”) returns 2. strtok Breaks a string into tokens by delimiters. strtok(“Hi, Chao”, “ ,”);
  12. 12. Lectures on Busy Bee Workshop 12 String in C – Library FunctionsString in C – Library Functions Function Purpose Example Strncpy Copy the specified number of characters strncpy(s1, “SVN”,2); Strncmp Compare two string upto given n character strncmp(“mo”, “more”,2); Stricmp Compare two strings alphabetically without case sensitivity. stricmp(“hu”, “Hu”); strlwr Converts string to all lowercase strlwr(“Hi”) returns hi. strupr Converts s to all uppercase strupr(“Hi”);
  13. 13. Lectures on Busy Bee Workshop 13 String in C – Library FunctionsString in C – Library Functions Function Purpose Example Strncat Appends a string to the end of another string up to n characters strncat(s1, “more”,2); Strrev Reverses all characters in s1 (except for the terminating null) strrev(s1, “more”);
  14. 14. Lectures on Busy Bee Workshop 14 String in C – Example program (Library Function)String in C – Example program (Library Function)

    Als Erste(r) kommentieren

    Loggen Sie sich ein, um Kommentare anzuzeigen.

  • RishabhKhanna17

    Aug. 13, 2016
  • FKFahim

    Dec. 2, 2017
  • ArifulSaimon

    Mar. 12, 2018
  • Jayupa97

    Apr. 15, 2018
  • PavaniNeppalli1

    Apr. 22, 2018
  • princeahan

    Oct. 16, 2018
  • kanishkarawalsetia

    Apr. 7, 2020
  • PaulMichael32

    Jun. 25, 2020
  • krishnamurthyRamasub1

    Jun. 29, 2020
  • dhanamsugi

    Oct. 21, 2020
  • VinothVinoth44

    Jan. 25, 2021
  • SharmilaDevi72

    Feb. 23, 2021
  • MandeepChoudhary9

    Mar. 4, 2021

C PROGRAMMING LANGUAGE

Aufrufe

Aufrufe insgesamt

7.561

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

7

Befehle

Downloads

580

Geteilt

0

Kommentare

0

Likes

13

×