Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Tutorial an easy ghostwritter


  • Please log in to reply
5 replies to this topic

#1 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 19 June 2008 - 05:56 AM

Hey again, I thought I will give a small tutorial how to make a ghostwritter. I have made this with some help of CC, so it turned out to be awsome.
So lets go on.

First lets build the input reader.
import java.util.*;//Using the scanner, instead of Keyboard reader
public class ghostwritter {

	protected static Scanner sc = new Scanner(System.in);//Setting up scanner
	
	public static void main(String[] arg) throws InterruptedException {
		
		System.out.println("Type in something ");//The input reader

Now we would want to use the input data, so...
String x = sc.nextLine();//This will allow the input data to be used(Note input was a string and will be used as a string)
Now on to the function, we want it to type out letter by letter with a delay. What I call a "ghostwritter"
for(int i=0; i<x.length(); i++) {//A loop thru the entire string
			System.out.print(x.charAt(i));//Catching very "x" one by one
			Thread.sleep(1000);//Put every "x" out it with one second delay(1000ms = 1 s)
		}
	}	
}

So here is the whole code
import java.util.*;
public class ghostwritter {

	protected static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] arg) throws InterruptedException {
		
		System.out.println("Type in something ");
		
			String x = sc.nextLine();

		for(int i=0; i<x.length(); i++) {
			System.out.print(x.charAt(i));
			Thread.sleep(1000);
		}
	}	
}
Hope it will be useful, and again sorry for my weak explaination...
  • 1

#2 MeTh0Dz

MeTh0Dz

    CC Leader

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1726 posts

Posted 19 June 2008 - 07:24 PM

I saw your code, was bored, and thought I'd show people how to do it in C++.
Here it is....

/* "Ghost Writer" In C++ */

#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int main() {
    char the_phrase[10000];
    int i;
    cout << "Enter a phrase you want to see outputted by the Ghost Writer: ";
    cin.get(the_phrase, 10000);
    cout << "\n\n";
    for (i = 0; i < strlen(the_phrase); i++) {
        cout << the_phrase[i];
        Sleep(100);
    }
    getch();
    return 0;
}

  • 1

#3 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 20 June 2008 - 01:00 AM

I saw your code, was bored, and thought I'd show people how to do it in C++.
Here it is....

/* "Ghost Writer" In C++ */

#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int main() {
    char the_phrase[10000];
    int i;
    cout << "Enter a phrase you want to see outputted by the Ghost Writer: ";
    cin.get(the_phrase, 10000);
    cout << "\n\n";
    for (i = 0; i < strlen(the_phrase); i++) {
        cout << the_phrase[i];
        Sleep(100);
    }
    getch();
    return 0;
}


Lol sweet but isn't out of topic :)?(This is the Java section xD)
  • 0

#4 MeTh0Dz

MeTh0Dz

    CC Leader

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1726 posts

Posted 20 June 2008 - 05:07 AM

Lol well I didn't want to start my own topic and write a full tutorial and all, so I figured this was the best place for it.
  • 0

#5 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 June 2008 - 05:54 AM

Nice tutorial/code Turk4n, +rep.
  • 0

#6 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 20 June 2008 - 07:49 AM

Thanks
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download