Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2012 -- CSC 2700 Section 02

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Printable ]  
   Archive Mirror
   NA Qualifier
   CSC 2700 Section 02
   Tureaud Hall 101
   6:30 PM - 8:20 PM
   2012 Spring
   2011 Fall


  • C related
    • Read an entire line (ignoring whitespace at begining and end of line): cnt = scanf("%[^\n]\n",str);
      • cnt has the following value possibilities:
        • 0 - blank line read
        • EOF - end of file encountered
        • positive number - characters read
      • %[^\n] is a format regular expression that says to get from beginning of line (^) until end of line (\n)
      • The second \n after the close bracket consumes the end of line
      • Note that this is vulenerable to overflow. If the line length is greater than str is declared for, it will continue to keep going (buffer overflow)
      • Note that white space at begining and end of line are lost
    • A better alternative that does not have a buffer overflow is: cnt = scanf("%10000[^\n]\n",str);
      • This assumes that str was declared to be 10000 characters long and will read a max of 10000 caracters
    • gets alternative that does not have stack overflow issues

[ Powered by Red Hat Linux ] [ Powered by Apache ] [ Powered by PHP ]

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Isaac Traxler