03-C-NoEvil - C No Evil A practitioner's guide Copyright University of Illinois CS 241 Staff 1 Playing with fire Program arguments Pointer

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff 1 C No Evil A practitioner's guide
Background image of page 1

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

View Full DocumentRight Arrow Icon
Playing with fire Program arguments Pointer arithmetic Output Stack memory Copyright ©: University of Illinois CS 241 Staff 2
Background image of page 2
ARGCount ARGValues int main(argc, char** argv) int main(argc, char* argv[]) argc Argument count The number of arguments that are passed to main in the argument vector argv . the value of argc is always one greater than the number of command-line arguments that the user enters. Copyright ©: University of Illinois CS 241 Staff 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
ARGCount ARGValues int main(argc, char** argv) int main(argc, char* argv[]) argv argument vector An array of string pointers passed to a C program's main function argv[0] is always the name of the command argv[argc] is a null pointer Copyright ©: University of Illinois CS 241 Staff 4
Background image of page 4
ARGCount ARGValues Copyright ©: University of Illinois CS 241 Staff 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
ARGCount ARGValues int main(argc, char** argv) int main(argc, char* argv[]) *(argv + argc) is NULL argv[argc] is NULL Copyright ©: University of Illinois CS 241 Staff 6
Background image of page 6
Type questions char**argv; What type is argv ? What type is *argv ? What type is **argv ? Copyright ©: University of Illinois CS 241 Staff 61
Background image of page 7

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

View Full DocumentRight Arrow Icon
Followup: Can add integers to pointers Compiler uses the type information long *p ; p [long][long][long] What address is p + 2 ? p + sizeof(long) * 2 Copyright ©: University of Illinois CS 241 Staff 7
Background image of page 8
Followup: output C stdio library functions printf("Hello %x %s %d", arguments…) fprintf(STDERR, "%x%s%d",…) Later… system call write(int,void*,size_t) Copyright ©: University of Illinois CS 241 Staff 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
printf Format Identifiers %d %i Decimal signed integer. %o Octal integer. %x %X Hex integer. %u Unsigned integer. %c Character. %s String. %f Double. %p Pointer. All of the parameters should be the value to be inserted. EXCEPT %s, this expects a pointer to be passed Copyright ©: University of Illinois CS 241 Staff 9
Background image of page 10
printf Basic Data Types #include <stdio.h> // for printf int main(int argc, char *argv[]) { // print "the date is: 01/25/2010", // i.e. 2- or 4-digit with leading zeros // using 32-bit 'long' datatype long day = 25; long month = 1; long year = 2010; printf("the date is: %02ld/%02ld/%04ld\n", month, day, year); // - print 8-digit hex value // - print a pointer value unsigned long ulID = 0x12345678;
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/04/2010 for the course CS 373 taught by Professor Kuma during the Spring '10 term at University of Illinois at Urbana–Champaign.

Page1 / 35

03-C-NoEvil - C No Evil A practitioner's guide Copyright University of Illinois CS 241 Staff 1 Playing with fire Program arguments Pointer

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online