removing blank spaces

This is a discussion on removing blank spaces within the C Programming forums, part of the General Programming Boards category; Suppose I write a couple paragraphs and save it as apple.txt. How do I put this file into an array ...

  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,796
    >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, 03:10 PM
  3. Replies: 3
    Last Post: 04-06-2005, 11:04 AM
  4. Replies: 1
    Last Post: 03-08-2005, 11:02 AM
  5. Removing spaces
    By chris1985 in forum C Programming
    Replies: 3
    Last Post: 12-22-2004, 08:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21