Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 24th, 2006, 3:36 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
File I/O problem

the following code is supposed to write to a file 60 characters per loop and then insert a new line character at the end of that line:
Quote:
#!/Perl/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");

open(DAT,">>Comments.txt");

$i=0;
$szlen=length $comment;

while($i<=$szlen)
{
print DAT substr($comment,$i);
print DAT "\n";
$i=$i+60;
}

close(DAT);
but some how this code is not printing 60 characters per line but instead more than 60 characters...........can any body please tell me what i am doing wrong and also tell me how i can correct this.............i thank you in advance for your replies.
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 24th, 2006, 4:53 PM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
okay sorry to waste your time people.......it was a silly mistake and after staring at the computer screen numlessly the penny dropped.........i was using the wrong string function to start with and some of my algorithms were out the window..........here is the new code after i have solved the problem:

Quote:
#!/Perl/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");

open(DAT,">>Comments.txt");

$i=60;
$j=0;
$szlen=length $comment;

while($i<$szlen+1)
{
print DAT substr($comment,$j,$i)."\n";
$j=$i;
$i+=60;
}
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 24th, 2006, 5:37 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Off topic, I'd suggest you learn to indent if your code is going to be presented to those other than yourself.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
Problem with file and array Marek C 9 Dec 28th, 2005 10:03 AM
Open File Problem :( Silent Visual Basic .NET 17 Dec 5th, 2005 2:30 AM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC