Home
Outline/Policy
Summary
Approach
References
Homework
View
Upload
Problems:
Archive
Categories
Guidelines
Coding
Tips
Contests:
Deloitte
Extra:
Grades
Class:
CSC 2700 Section 04
Tureaud 109
Tuesday
5:30 PM - 7:30 PM
Previous:
2011 Fall
|
|
Tips
- 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
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
|