Lab1-CProgramming

Lab1-CProgramming - LAB 1 C Programming PROGRAMMING IN C...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
LAB 1 C Programming
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
PROGRAMMING IN C Most operating systems are implemented in lower level languages C and assembly are the common choices You’ve acquired the basic programming skill in C++. In here, we are going to give you an overview of C programming. Mainly highlighting the features that you might not have seen in C++
Image of page 2
STRUCTURE OF C PROGRAMS The program structures of C and C++ are almost identical To compile, use “ gcc gcc Lab1-Example1.c o example1 To run it ./example1 // Lab1-Example1.c #include <stdio.h> int main() { printf( "Beware the differences between C & C++ !!\n" ); getchar(); return 0; }
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
I/O C doesn't have stream operators; you cannot use cin and cout For output to screen, use printf() How to use it? Read its Linux manpage: man 3 printf int printf(char *format, arg list ...) This function takes a variable number of arguments Prints to standard output the list of arguments according to the specified format string The first one is a string describing the formatting information of the rest of the arguments
Image of page 4
PRINTF() In the formatting string, the character “%” is special The following character of it describes the format of a value to be displayed. %d for int, %f for float, %s for string Example Output is: integer is: 10 , float is: 6.54 , string is: " So what " int abc=10; float efg=6.54321; printf("integer is: %4d , float is: %.2f , string is: \" %s \" \n", abc , efg , " So what ");
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
SCANF() For input from keyboard, use scanf() or . . . man 3 scanf int scanf(char *format, args .... ) Reads from standard input and puts input in address of variables specified in args list. Format control string similar to printf() Example // Lab1-Example2.c #include <stdio.h> int main() { int number; float fnum; printf( "Please enter a number then follow by a float number: " ); scanf( "%d %f", &number, &fnum ); printf( "You entered %d & %f\n", number, fnum ); getchar(); return 0; }
Image of page 6
COMPATIBILITY (1) In earlier versions of C, declarations could appear only at a block's beginning, before any other statements.
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern