Read text from file skipping any spaces or empty lines

前端 未结 1 1818
猫巷女王i
猫巷女王i 2021-01-29 16:07

Hi. I need to read several files without spaces or empty lines between characters.They can have different layouts, such as 1.txt, 2.txt or 3.txt:


1条回答
  •  爱一瞬间的悲伤
    2021-01-29 16:38

    I think you're asking how to read in a text file, ignoring spaces and empty lines. Please clarify your question so that we can help you better.

    Here's something to get you started:

    You could read in the entire file, then remove anything you don't want. The following post agrees with my experience that your application will probably run faster that way: Reading a file faster in C

    If you agree with that approach, this next post will show you how to read the text file into a buffer, with some error handling: Reading the whole text file into a char array in C

    Then you can use something like this to remove the spaces, and something similar for the extra new lines: Function to remove spaces from string/char array in C

    I hope this helps get you started, and perhaps someone will find time today to post some code for you.

    0 讨论(0)
提交回复
热议问题