Computer Science Canada comparing a file line by line |
Author: | dchini [ Sat Oct 18, 2008 5:51 pm ] | ||
Post subject: | comparing a file line by line | ||
Alright the code i have right now compares two files line by line. What i want my code to do is to make sure the words on the line are the same (it doesnt matter how many spaces there are) The code below checks char for char i believe..... any help checking word for word or how to get this line for line to work would be extremely helpful
|
Author: | wtd [ Sat Oct 18, 2008 6:26 pm ] |
Post subject: | RE:comparing a file line by line |
I would like to suggest moving some stuff out into separate functions. For instance, you need to compare words ignoring whitespace. Try creating a "normalize_whitespace" function which takes in a string and returns a new string with extraneous whitespace removed. "Hello, world " would become "Hello, world". |
Author: | Pockets [ Tue Oct 21, 2008 5:19 pm ] |
Post subject: | RE:comparing a file line by line |
This looks like a job for strtok()! Just remember to use ' ' as your delimiter. Strtok will take continguous delimiters (eg: two or more spaces) as a single delimiter, so it does most of the work for you. Don't forget that when it's done tokenizing, it returns NULL. |
: |