Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with some Input/Output....
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Terror Byte




PostPosted: Sun Feb 19, 2006 11:59 am   Post subject: Help with some Input/Output....

Okay I have to do several things with a couple of files.

I need to remove punctuation marks from a file.

code:

const PUNC := ",.:;?!'"
var streamnumber : int
var streamnumber2 : int

open : streamnumber, "C:/Adeel/Turing/story.txt", get
open : streamnumber2, "C:/Adeel/Turing/no_punc.txt", put

loop
    exit when eof (streamnumber)
    get : streamnumber, letter
    for i : 1 .. 7
        if letter = PUNC (i) then
            letter := " "
        end if
    end for
    put : streamnumber2, letter ..
end loop

close : streamnumber
close : streamnumber2


Basically, I can remove the punctuation marks but they get replaced with a space... How do I get rid of the space? I've tried replacing it with "^H" which the Turing Help says acts like a backspace or something..

Can anyone help me out here?
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sun Feb 19, 2006 12:28 pm   Post subject: Re: Help with some Input/Output....

Terror Byte wrote:

code:

        if letter = PUNC (i) then
            letter := " "
        end if



Look, a space! I wonder what will happen if I...Laughing By the way, your code won't work. I mean, apart from having not declared 'letter'. You're trying to get it to do something (check for punctuation), but instead you're setting up an equality test - not what you want to be doing. Instead, look into the index() function.
Terror Byte




PostPosted: Sun Feb 19, 2006 12:31 pm   Post subject: (No subject)

Oh I did declare letter as a char.. Just forgot to put it in the code.. It's part of a bigger exercize.

And it does seem to work. The file I get mirrors the original exactly except all the punctuation marks are gone and replaced with a space.

I just want to remove the punctuation marks and remove that space as well.
Cervantes




PostPosted: Sun Feb 19, 2006 12:38 pm   Post subject: (No subject)

Sadly, you can't do something like this:
code:

foo (12) := ""

Instead, you have to settle for this:
code:

var foo := "Hello World! Ninja Pirate Wooble Foo."

% Find a punctuation mark at letter 12.
foo := foo (1 .. 11) + foo (13 .. *)

put foo
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: