Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Introduction to C Programming CE Lecture 1 Introduction to C.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, , 2.6, 3.1, 5.1, , , , Ch. 8 ; Programming.
Guide To UNIX Using Linux Third Edition
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
CSE : Programming in C Instructor: Lei Wang Office: Dreese Lab 474 Office Hour: Friday.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Computer Science 210 Computer Organization Introduction to C.
“C” Programming Language CIS 218. Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Programming With C.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Programming
Introduction to C 2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park 1.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
Agenda Computer Languages How to Write a Simple C Program
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
Minimal standard C program int main(void) { return 0 ; }
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
C is a high level language (HLL)
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Hank Childs, University of Oregon April 15 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Introduction to C Topics Compilation Using the gcc Compiler
UMBC CMSC 104 – Section 01, Fall 2016
Computer Science 210 Computer Organization
C Programming.
A bit of C programming Lecture 3 Uli Raich.
Introduction to C Language
Computer Programming Techniques Semester 1, 1998
C Programming Hardik H. Maheta.
C Language By Sra Sontisirikit
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
History of ‘C’ Root of the morden language is ALGOL It’s first
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
CSE 351 Section 1: HW 0 + Intro to C
Introduction to C Topics Compilation Using the gcc Compiler
C Basics.
Introduction to C Programming Language
Programmazione I a.a. 2017/2018.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Computer Science 210 Computer Organization
Functions I Creating a programming with small logical units of code.
C Programming.
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C EECS May 2019.
C – Programming Language
An Overview of C.
C Programming.
Introduction to C Topics Compilation Using the gcc Compiler
Functions I Creating a programming with small logical units of code.
Presentation transcript:

Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex of with large amounts of data: Use a C program Examples –Command: pipes and redirection to search files –Shell script: apply a particular kind of filter using different parameters at different times –C program: create a simulation program

C Advantages and Disadvantages Advantages –Super fast –Concise set of syntax –Portable: all systems can compile c –Very popular Disadvantages –Not object oriented meaning that procedures and functions are written to operate on data constructs

History 1972 –Dennis Ritchie creates the c language –The classic book by Kernigham and Ritchie defines the syntax for this language. –1990 ANSI C with some minor extensions –1999 ANSI C with some more minor extensions 1979 –C++ which is C with classes –Additional enhancements since then 1990s: Java – programming language based on C++ syntax 2002: C# –.net language with characteristics of Java and C++ Note: If you know Java, you know lots of C ("Just Like Java" or JLJ)

Making a C Program Create your program >vi hello.c Complile and link –The standard UNIX command: >cc –The GNU command: >gcc –Flags -o creates an executable named instead of a.out -g create symbolic information for the gdb debugger -l include a run time library -L search path for libraries Debug: >gdb executable (we will cover this later) To run: just type or./ if. is not in the search path

Development Cycle 1.Design and code 2.Editor to enter the code: program.c 3.Compile: program.o 4.Link: program 5.If link errors, return to step 2 6.Execute program 7.If logic errors return to step 1 Note: Steps 3 and 4 is normally done by gcc in one step

Hello World Program /* hello.c prints "hello world" April 29, 2002: Kevin Sahr */ #include int main(int argc, char* argv[]) { printf("hello world\n"); return 0; } /* main */ 1./* to */ are comments 2.include merges source from stdio.h 3.main function runs first 4.return 0 tells shell result ok, return # indicates an error 5.printf is like java println, but with more features 6.the * is used to reference an array called argv 7.argc is the number of command line arguments 8.argv[0] has the program name, command line arguments are in argv[1].. argv[n] 9.{ and } are JLJ JLJ: each statement ends with ;

C Program Structure Comments –At top: File name, date, author, purpose –Throughout: clarify code as needed Preprocessor directives –C programs run through a preprocessor phase first –This phase: Include other source files, perform modifications to the source file –Preprocessor directives do not end with ; Include the main function Include other functions (Subject for a later week)

Comments C comments are /* … */ –Do not nest comments –In labs, include the name of the file, your name, and date at the top of every file you submit –Other comments will be optional, but use when the code is not easy to follow The // format were introduced in C++ –They presently are not part of C –They are proposed for the next version of C

Header files: stdio.h and stdlib.h Includes: analogous to Java Includes –stdio.h is a text file containing prototypes for stream based I/O functions –stdlib.h another text file containing prototypes to the C "standard library" Prototypes: –analogous to Java Interfaces –function bodies completed when linking

main() function main() –Every C program must have a main function –Analogous to Java "static void main(String[] args)" –Syntax: int main(int argc, char *argv[]) argc: number of arguments argv: an array of argument strings –return statement returns to the caller main() function returns to the shell return 0; tells the shell that the run was successful return #; returns an error code to the shell

Converting String Data Commonly used functions –Ascii to integer: atoi(string); –Ascii to float: atof(string); –String to double: strtod(char *start, char *end); Example Int main(int argc, char *args[]) { int x = atoi(args[1]); double y = atof(args[2]); double z = strtod(args[2], NULL); // entire string }