Lab1_Parsing - Line by Line Parsing in C Computer Science...

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

View Full Document Right Arrow Icon
Computer Science Department University of Central Florida Line by Line Parsing in C COP 3502 Recitation Session
Background image of page 1

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

View Full DocumentRight Arrow Icon
Line by Line Parsing in C page 2 Parsing Typical parsing in C: We read input from keyboard and files as individual tokens separated by white space scanf and fscanf are used for this They read successive tokens from the input They read until white space is encountered and then it stops The next call of scanf picks up from there and reads the next token When is this parsing method useful? If we know how many tokens will be inputed, and we know what each token represents integer, float, string, etc.
Background image of page 2
Line by Line Parsing in C page 3 Parsing Typical parsing in C: But what if we don’t know how many tokens we will read in? Say it is a list of Math classes for Spring 2010 MA 245 MA 318 MA412 … Maybe the list has 10 classes, or 20 classes, or more How would we go about reading this in?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Line by Line Parsing in C page 4 Parsing Typical input files: In these types of files, spaces are usually part of the input Such as the space between a first and last name Tabs and newlines are usually the delimiters Stuff that separates the data Standard processing is to read one entire line at a time Which could have several pieces of information Then use a “string tokenizer” to parse out the different pieces of data in the line.
Background image of page 4
Line by Line Parsing in C page 5 Parsing How do we make this happen: Start with fgets function: Allows us to read in an entire line at once Meaning, until the next newline char *fgets(char *restrict
Background image of page 5

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

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

This note was uploaded on 09/21/2011 for the course COP 3330 taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 16

Lab1_Parsing - Line by Line Parsing in C Computer Science...

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

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