Trusted by +2 million users,
assist thousands of students everyday
assist thousands of students everyday
Showing pages 1 to 8 of 44 pages
1Click to edit Master text stylesSecond levelThird levelFourth levelFifth levelEECS 2031Software ToolsModule 5 – Introduction to C
2TextbookThe C Programming Language (2nd edition)by Brian Kernighan and Dennis RitchiePrentice Hall Software Series
3C vs. Java•Java-like (actually Java has a C-likesyntax), some differences•No garbage collection•No classes•No exceptions (try ... catch)•No String type•Pointers
4First C Program (first.c)#include <stdio.h>main() {printf(“hello, world \n”);}Note:#include <filename.h>replaces the line by the actual file beforecompilation starts.
5Basic I/O•Every program has astandard inputand astandard output.•By default, keyboard and monitor,respectivelyInput functionsOutput functionsscanf()printf()getchar()putchar()fgets()fputs()
6Output is easy... (celsius.c)•Most of the time, useprintf()•Very similar to Java•See Chapter 7 in the textbook•Returns the number of characters printed•Can also useputchar()for a singlecharacter
7Input is more complicated•Several functions for input shouldneverbe used because they are unsafe•They are still in the standard librarybecause a lot of code out there uses them•Avoid usinggets()as well asscanf()for strings•Recommended way to read input:getchar()orfgets()+sscanf()
8getchar()•To read one character at a time from thestandard input(the keyboard by default):int getchar(void)•Returns the next input character eachtime it is called•Returns EOF when it encounters end offile.•EOF input: Ctrl-D (Unix) or Ctrl-Z(Windows).

You’re reading a preview
To View Complete Document
Become a Desklib Library Member.
Subscribe to our plans