Thread: removing blank spaces

  1. #1
    Bash
    Guest

    Question removing blank spaces

    Suppose I write a couple paragraphs and save it as apple.txt. How do I put this file into an array and remove the blank spaces.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How do I put this file into an array and remove the blank spaces.
    Removing the blank spaces is easy if you plan to write the array back to the file, simply print the non-whitespace characters to the file. The problem comes in placing the input in an array, it's not terribly difficult, but simply writing from the input file to an output file without the spaces is much easier and more efficient since you don't have to shuffle an array or create a second buffer:
    Code:
    while ( ( ch = fgetc ( instream ) ) != EOF )
      if ( !isspace ( ch ) ) fputc ( ch, outstream );
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check for blank spaces in a string
    By BENCHMARKMAN in forum C Programming
    Replies: 19
    Last Post: 03-12-2008, 06:14 PM
  2. Replies: 4
    Last Post: 12-01-2007, 04:10 PM
  3. Replies: 3
    Last Post: 04-06-2005, 11:04 AM
  4. Replies: 1
    Last Post: 03-08-2005, 12:02 PM
  5. Removing spaces
    By chris1985 in forum C Programming
    Replies: 3
    Last Post: 12-22-2004, 09:23 AM