C Stuff CS 2308.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
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.
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.
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:
Lesson 10 Characters, C-Strings, and the string Class CS1 Lesson John Cole1.
CS Nov 2006 C-strings.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
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.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
C vs. C++ I/O Declaration Placement Strings Minor syntax differences (ala enum)
Strings, Slide Fundamental Programming Strings.
CMSC 104, Version 8/061L25Strings.ppt Strings Topics String Libraries String Operations Sample Program Reading Sections
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 7 Enumerated Types and Strings Types.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Lecture 2A Data Types Richard Gesick
LINKED LISTS.
Lesson #8 Structures Linked Lists Command Line Arguments.
Strings CSCI 112: Programming in C.
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
A bit of C programming Lecture 3 Uli Raich.
Fundamentals of Characters and Strings
Lecture 8 String 1. Concept of strings String and pointers
C Programming Tutorial – Part I
Programming Languages and Paradigms
Command Line Arguments
Command line arguments
CSE 303 Concepts and Tools for Software Development
Characters, C-Strings, and More About the string Class
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Programming Paradigms
Command-Line Arguments
C Programming:Part 3 Characters and Strings File Processing Exercise.
Arrays in C.
Instructor: Ioannis A. Vetsikas
Character Strings Lesson Outline
Standard Version of Starting Out with C++, 4th Edition
Computer Science 210 Computer Organization
CS111 Computer Programming
Object Oriented Programming COP3330 / CGS5409
CS 2308 Exam I Review.
Engr 0012 (04-1) LecNotes
INC 161 , CPE 100 Computer Programming
Pointers and Pointer-Based Strings
Strings A collection of characters taken as a set:
Chapter 9 One-Dimensional Arrays
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
Strings Dr. Soha S. Zaghloul updated by Rasha ALEidan
Chapter 8 Character Arrays and Strings
CPS120: Introduction to Computer Science
Engineering Problem Solving with C++, Etter
Standard Version of Starting Out with C++, 4th Edition
C By Example The assumption is that you know Java and need to extend that knowledge so you can program in C. 1. Hello world 2. declarations 3. pass.
Character Arrays char string1[] = “first”;
Strings #include <stdio.h>
Programming Languages and Paradigms
EPSII 59:006 Spring 2004.
C Characters and Strings
Introduction to Problem Solving and Programming
Presentation transcript:

C Stuff CS 2308

Major differences between C and C++ Header files When including libraries, include the “.h” #include <string.h> No Constants Typically use #define to identify constants Different I/O libraries Use <stdio.h> printf and scanf instead of cout and cin Strings No strings in C

C strings There is no “string” data type in C Use arrays of characters Always null terminated “\0” Need one more space than the number of characters you need to store. char name[26]; /*to hold 25 chars and null */ No direct comparison for equality or direct assignment NO str1 = str2 NO str1 == str2 OR str1 < str2

String functions in C Found in <string.h> Examples Page 559-560 in text Examples strcpy strcmp strlen strcat atoi atof itoa

Other differences between C and C++ No namespaces Not a real issue for the types of programs we are creating, but important for larger projects. No “pass by reference” Very important. Let’s see how we can make functions work without it. No bool data type Because of the frequency of boolean expressions we typically find a way to use a simulated type. #define FALSE 0 #define TRUE 1

More differences between C and C++ No const qualifier All variables must be declared in functions before the first executable statement No function overloading Serious drawback for object-oriented programming

Command Line Arguments As you have seen in Linux, there are often command line arguments to programs. How do we use them in programs? “argc” is the number of arguments “argv” is an array of strings int main (int argc, char* argv[]) { }