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

Info icon This 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
Image of page 1

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

View Full Document Right 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.
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?
Image of page 3

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

View Full Document Right 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.
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
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
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