Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 09-10-2008, 08:02 PM   #21
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

The space is irrelevant. But didn't it work in the end (I'm lost)?

BTW Data, kudos! What language did you use? And Play, you were really lucky Data had the free time to spare.
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 10-10-2008, 01:05 AM   #22
Playbahnosh
The Peacemaker
 
Playbahnosh's Avatar


 
Join Date: Apr 2005
Location: Veszprem, Hungary
Posts: 353
Send a message via MSN to Playbahnosh
Default

Quote:
Originally Posted by Japofran View Post
The space is irrelevant. But didn't it work in the end (I'm lost)?

BTW Data, kudos! What language did you use? And Play, you were really lucky Data had the free time to spare.
Yeah, I'm pretty fortunate, thanks to Data, all is okay now.

And yes, it worked for Data but not for me, for some reason. I tend to be a perfectionist in matters like this, so I won't make the same mistake again, and even if it worked, I wanted to know why it didn't for me. But it's kinda irrelevant now, you are right :amused:
__________________
The Master of Light and Darkness

"Don't fight the bad things in life! Find the good one! They are everywhere! Don't spend your life fighting for goals you can never reach! Live for the moment!"


BEWARE: I'm using the forums as a personal blog!
Playbahnosh is offline                         Send a private message to Playbahnosh
Reply With Quote
Old 10-10-2008, 06:37 AM   #23
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

the only thing I can think of is the line ends being different. I did convert them to unix line ends. It shouldn't matter as I compiled the executable for windows, but maybe that doesn't convert the line ends internally afteral, or maybe it needed a switch.

I used C++ to program it, it is a quick getting the job done piece of code.

Let me post it here. Don't bother with pointing out all C-isms and other things which I could have done better. I know them myself as well.
Code:
/* Copyright Data */

#include <string>
#include <iostream>

int main (int argc, char *argv[]) {
        std::string templine;
        std::string index, timeindex, text;
        std::string index2, timeindex2, text2;

        //Get initial record:
        getline (std::cin, index);
        getline (std::cin, timeindex);
        templine = "";
        do {
                getline (std::cin, templine);
                text += templine;
                text += "\n";
        }
        while (templine != "");

        while (std::cin) {
                getline (std::cin, index2);
                getline (std::cin, timeindex2);
                templine = "";
                do {
                        getline (std::cin, templine);
                        text2 += templine;
                        text2 += "\n";
                }
                while (templine != "");

                //writeout record:
                std::cout << index << std::endl;
                std::cout << timeindex << std::endl;
                std::cout << text2;

                //move up:
                index = index2;
                timeindex = timeindex2;
                text2 = "";
        }
        return 0;
}
__________________
Flowing with the stream of life

Last edited by Data; 10-10-2008 at 06:39 AM.
Data is offline                         Send a private message to Data
Reply With Quote
Old 10-10-2008, 01:00 PM   #24
Playbahnosh
The Peacemaker
 
Playbahnosh's Avatar


 
Join Date: Apr 2005
Location: Veszprem, Hungary
Posts: 353
Send a message via MSN to Playbahnosh
Default

Wow! Thanks for sharing. Maybe you could upload this to sourceforge or something, maybe other people have the same problem
__________________
The Master of Light and Darkness

"Don't fight the bad things in life! Find the good one! They are everywhere! Don't spend your life fighting for goals you can never reach! Live for the moment!"


BEWARE: I'm using the forums as a personal blog!
Playbahnosh is offline                         Send a private message to Playbahnosh
Reply With Quote
Old 10-10-2008, 01:40 PM   #25
_r.u.s.s.
I'm not Russ
but an ex-alektorophobic
 
_r.u.s.s.'s Avatar


 
Join Date: May 2005
Location: Nitra, Slovakia
Posts: 6,533
Default

whole sourceforge project dedicated to skipping subtitle positinos to the next line?
__________________
_r.u.s.s. is offline                         Send a private message to _r.u.s.s.
Reply With Quote
Old 10-10-2008, 02:01 PM   #26
Playbahnosh
The Peacemaker
 
Playbahnosh's Avatar


 
Join Date: Apr 2005
Location: Veszprem, Hungary
Posts: 353
Send a message via MSN to Playbahnosh
Default

You really can't take a joke, do you?

But a program to correct every sorts of problems with subtitles won't be a too bad idea, now you mention it. Maybe someday, when I learn to program real good, I might do something like that.
__________________
The Master of Light and Darkness

"Don't fight the bad things in life! Find the good one! They are everywhere! Don't spend your life fighting for goals you can never reach! Live for the moment!"


BEWARE: I'm using the forums as a personal blog!
Playbahnosh is offline                         Send a private message to Playbahnosh
Reply With Quote
Old 10-10-2008, 04:54 PM   #27
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

Quote:
Originally Posted by Data View Post
Don't bother with pointing out all C-isms and other things
Don't worry about that, first I'm not fluent at programming since I use it so little, second C is what I grew up with and although I pushed myself to learn ++, I have used C++ not at all instead of little so it's not natural in me. (And actually see no comparative advantage for small one-person projects. It may be nice to use + instead of strcat() though. LOL And C isn't certainly obsolete nor redundant, I'm not the only one to think so, whereas C++ could very well be and sure is a messy language.)

Good job, I don't think there's much more ellegant code to accomplish the same.

The only thing I can think of is why you bother to declare the namespace once and again, instead of declaring once "using namespace std" at the start of the code. And why you declare main's arguments that you aren't using instead of declaring it (void)--or () which is the same. But maybe you have reasons. And sorry if I have just pointed what you know yourself after you warned me not to.

Very well done. And I bet the problem has the compiler to blame, it's up to it to make portable code portable as promised.
__________________
Life starts every day anew. Prospects not so good...
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 10-10-2008, 07:37 PM   #28
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

Thank you for kind remarks.

I use using namespace std; quite often, but as I published the code I made a bit more robust for copy and paste work by including the correct namespace.

I tend to forget the possibility to omit the arguments of main.
Returning a value is good practice, especially if the utility can be used in shell scripts.

My Cism were (as far as I'm concerned)

Code:
templine = "";
instead of
Code:
templine.clear()
and
Code:
templine != ""
instead of
Code:
!templine.empty()
But the Cism are actually smaller and for me at least as intuitive as the C++ things. (long live the operator overloading )
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 10-10-2008, 10:30 PM   #29
Japo
Autonomous human
 
Japo's Avatar


 
Join Date: Mar 2006
Location: ,
Posts: 4,613
Default

Quote:
Originally Posted by Data View Post
But the Cism are actually smaller and for me at least as intuitive as the C++ things.
True, maybe people who have learnt to program oriented to objects from the start don't get how all those abstractions are both added power and added burden. You have to learn the object libraries. And in some cases a more low-level code is not more clumsy nor illegible and sometimes the contrary. That's why I think of objects as a tool rather than a philosophy for the whole of all projects; and they don't really show their full power but as an interface between different programmers. Using object orientation as a way to make learning programming easier just creates bad programmers in general.

Usually you can't be sure if you can really get away with "C-isms" and the like. Something may not be in the standard and yet your compiler may support it and others won't. (It's not the case and your code is robust.) And you're not supposed to know, because information hiding is a sought effect of object orientation.

As a matter of fact using an overloaded assignment operator with a string is not a C-ism at all... Actually the robust C code to clear a string or check if it's not empty is very brief and immediately recognizable:

Code:
*templine = '\0';
Code:
while ( *templine != '\0' );
(Actually I could write just 0 instead of '\0', couldn't I? Hm better safe than sorry.) Of course templine would here be a C string (pointer to char), not a string object. I can't do this stuff with objects and I'm not supposed to, their innards are "private".

But I'm rambling...
__________________
Life starts every day anew. Prospects not so good...

Last edited by Japo; 10-10-2008 at 10:57 PM.
Japo is offline                         Send a private message to Japo
Reply With Quote
Old 11-10-2008, 03:10 AM   #30
Playbahnosh
The Peacemaker
 
Playbahnosh's Avatar


 
Join Date: Apr 2005
Location: Veszprem, Hungary
Posts: 353
Send a message via MSN to Playbahnosh
Default

Quote:
Originally Posted by Japofran View Post
Usually you can't be sure if you can really get away with "C-isms" and the like. Something may not be in the standard and yet your compiler may support it and others won't.
Oh boy, don't get me started on that one.
I have to take C and C++ classes here on the university, and it is a constant pain in the aß, as to which compiler to use. For many years, the uni used Microsoft's Visual Studio for C programming, but the license expired, and they didn't renew it. They started using Eclipse because it's free, but the course's codes, books and learning material were optimized for Visual Studio, and a great many things, what worked in VS, didn't work in Eclipse and vice versa. Just think about it, you make a project for class in C or C++, you run it and works fine, you bring it in for class and it won't work there. Who's to blame for that? Ususally us, students.:notrust:
__________________
The Master of Light and Darkness

"Don't fight the bad things in life! Find the good one! They are everywhere! Don't spend your life fighting for goals you can never reach! Live for the moment!"


BEWARE: I'm using the forums as a personal blog!
Playbahnosh is offline                         Send a private message to Playbahnosh
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Castlevania movie script revealed TheChosen Blah, blah, blah... 16 18-07-2008 06:41 PM
Abandonia Script? jourdan Old Suggestions 4 09-07-2007 09:24 AM
Script Not Working After Migrate Reup Old Suggestions 1 25-08-2006 11:58 AM
Annoying Script Prompt -RESOLVED guesst Old Suggestions 7 28-07-2006 01:00 AM


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
 


The current time is 10:18 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.