• Strings

    What is a string?:

    • collection of characters
    • more specifically, an array of char's

    Why are strings important?:

    • strings allow you to process words, and eventually sentences
    • handling multiple individual char's by itself is not as intuitive as handling a string of characters

    How to picture a string?:

  • Implementing Strings

    How to use a string?:

    • same as arrays: declare it with the size, initialize it, and use (set, change, or display) it
    • things to note about strings:

    A simple example using strings:

    This program initializes a string and the displays it

    string.c:

    output:

    display the letters:
    word[0]: c
    word[1]: a
    word[2]: r
    word[3]:
    display the word using characters
    car
    display the word using a string
    car

    Null Character

    Be aware of the null character \0 when working with strings

    Read more about the null character at http://en.wikipedia.org/wiki/Null_character

    null_character.c:

    output:

    car
    c
  • String and the null character

    Ask the user to enter in a word that is 10 letters or less

    print out the letters of the word individually

  • Assignment

    Homework Problem 21.1, at the end of this problem you should submit to Laulima:

    • a file named UHusername_21_1.c
      • example:
      • zhaol_21_1.c
    • Please note that this assignment has an extended due date because of its complexity. Please plan accordingly.

    • write a program that asks the user to enter in a word

      the program then outputs the letters of the word in alphabetical order

      assume the user will only enter in words that are 10 letters long

      assume the user will only enter in lowercase letters

    • Test Case 1:
      Please enter a word:
      [user enters zebra]
      You've entered: zebra
      I've alphbetized it to: aberz 
      
  • Optional Assignments

    Optional assignments are not graded and does not need to be turned in. It is intended to give you more practice (if you want it) using the programming concepts discussed in lecture. Some optional assignments are intended to introduce related concepts (if you care about it) not discussed in this course to broaden your knowledge about programming in general.

    If the optional assignment is modifying a required assignment, be sure to leave your previous assignment work untouched by copying them to a new folder for the optional assignment and modify only the files in the new folder

    Write a program that accepts a message from the user and then posts it to Twitter (https://twitter.com/ee160_uh_manoa):

      Instructions:
    • Include and use this function to post your message to Twitter:

    Click here for the answer if you get stuck: