C Programming Language Assignment

Added on - 18 Mar 2021

  • 44


  • 2042


  • 31


  • 0


Trusted by +2 million users,
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. JavaJava-like (actually Java has a C-likesyntax), some differencesNo garbage collectionNo classesNo exceptions (try ... catch)No String typePointers
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/OEvery 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 JavaSee Chapter 7 in the textbookReturns the number of characters printedCan also useputchar()for a singlecharacter
7Input is more complicatedSeveral functions for input shouldneverbe used because they are unsafeThey are still in the standard librarybecause a lot of code out there uses themAvoid usinggets()as well asscanf()for stringsRecommended 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 calledReturns EOF when it encounters end offile.EOF input: Ctrl-D (Unix) or Ctrl-Z(Windows).
You’re reading a preview
Preview Documents

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document