C project on TypeWriter

Computer Science & Engineering Discipline,

Khulna University, Khulna.

Type Writer Project in C

Submitted by

Student ID                   Name

180226   –    Md. Shazzadul Ahsan

180229   –    Md. Ashadousjaman Rony

180232   –    Mehedi Hasan Shanto

180235   –    Md. Azizul Haque.

 

 

Introduction: Typing is the basic command to run a computer and your typing speed plays vital role while working in computer to save time. Here I have presented a Typing Tutor Project in C to measure user’s typing speed and to enhance their typing speed. This is a simple console application written in C programming language, and compiled using GNU GCC compiler on Code::Blocks IDE.

The source code of Typing Tutor Project in C consists of over 250+lines of code. The project source code effectively utilizes the user defined functions and the concept of file handling. You can directly download the application file and source code of this project from the link below.

How to play

  • Download the project files from google drive… or github…

    note: keep main.cpp, first.txt and typingHistory.txt in the same directory…

  • Firstly when you run the game you will see the start menu with multiple options. The outlook will be like this…

  • If you choose option ‘1’ to play game from the keyboard , you will get a window.. here

Enter your name here to save your data, you can start typing now as following text

Then you get your typing accuracy and typing speed in WPM with mistakes and get a window like this

Press ‘2’ to show the main menu from any where… here is the link…

  • We keep some instruction for you in option ‘3’ like this… link…

  • Press ‘4’ for history in this game. As you can compare with others…
    You can compare you accuracy and word. You will also see your typing time

link…

Important function use in Project

The major user defined functions used in the source code of this project are:

strtok(): strtok() is one of the inbuilt string function in c programming which is used to split the given string with the given character. The following diagram clearly illustrate the working principle of strtok() :- link

strtok() split the string into parts, wherever the given character is present in the string. Splitting is done by replacing a user mentioned delimitting character with ‘\0’ i.e) Null character.

Syntax –strtok()

  • strtok() accepts two parameters,

  • First parameter must be a string and second parameter must be a character.

  • Second parameter must be a delimiting characters like , : ;

  • To use strtok() inbuilt string functions in C, we need to declare #include<string.h> header file.

  • Syntax

strtok(string, charecter);

gets():

The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.

Declaration

char *gets(char *str)

Parameters

  • str − This is the pointer to an array of chars where the C string is stored.

Return Value

This function returns str on success, and NULL on error or when end of file occurs, while no characters have been read.

fopen():The C library function FILE *fopen(const char *filename, const char *mode) opens the filename pointed to, by filename using the given mode.

Following is the declaration for fopen() function.

FILE *fopen(const char *filename, const char *mode);

Parameters

  • Filename − This is the C string containing the name of the file to be opened.

  • Mode − This is the C string containing a file access mode. It includes −

Sr.No.

Mode & Description

1

“r”

Opens a file for reading. The file must exist.

2

“w”

Creates an empty file for writing. If a file with the same name already exists, its content is erased and the file is considered as a new empty file.

3

“a”

Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist.

4

“r+”

Opens a file to update both reading and writing. The file must exist.

5

“w+”

Creates an empty file for both reading and writing.

6

“a+”

Opens a file for reading and appending.

Return Value

This function returns a FILE pointer. Otherwise, NULL is returned and the global variable errno is set to indicate the error.

fclose():The C library function int fclose(FILE *stream) closes the stream. All buffers are flushed.

Declaration

Following is the declaration for fclose() function.

int fclose(FILE *stream);

Parameters

  • Stream − This is the pointer to a FILE object that specifies the stream to be closed.

Return Value

This method returns zero if the stream is successfully closed. On failure, EOF is returned.

fprintf():

The C library function int fprintf(FILE *stream, const char *format, …)sends formatted output to a stream.

Declaration:

Following is the declaration for fprintf() function.

int fprintf(FILE *stream, const char *format, …);

fseek():The C library function int fseek(FILE *stream, long int offset, int whence) sets the file position of the stream to the given offset.

Declaration

Following is the declaration for fseek() function.

int fseek(FILE *stream, long int offset, int whence);

fgets():The C library function char *fgets(char *str, int n, FILE *stream) reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.

Declaration

Following is the declaration for fgets() function.

char *fgets(char *str, int n, FILE *stream)

Parameters

  • str − This is the pointer to an array of chars where the string read is stored.

  • n − This is the maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.

  • stream − This is the pointer to a FILE object that identifies the stream where characters are read from.

Return Value

On success, the function returns the same str parameter. If the End-of-File is encountered and no characters have been read, the contents of str remain unchanged and a null pointer is returned.

If an error occurs, a null pointer is returned.

rewind():

The C library function void rewind(FILE *stream) sets the file position to the beginning of the file of the given stream.

Declaration

Following is the declaration for rewind() function.

void rewind(FILE *stream)

Parameters

  • stream − This is the pointer to a FILE object that identifies the stream.

Returns: This function does not return any value.

ftell():

Description

The C library function long int ftell(FILE *stream) returns the current file position of the given stream.

Declaration

Following is the declaration for ftell() function.

long int ftell(FILE *stream);

Parameters

  • stream − This is the pointer to a FILE object that identifies the stream.

Return Value

This function returns the current value of the position indicator. If an error occurs, -1L is returned, and the global variable errno is set to a positive value.

srand():

Description

The C library function void srand(unsigned int seed) seeds the random number generator used by the function rand.

Declaration

Following is the declaration for srand() function.

void srand(unsigned int seed);

Parameters

  • seed − This is an integer value to be used as seed by the pseudo-random number generator algorithm.

Return Value

This function does not return any value.

We use this function to take random input from file.

system():

The C library function int system(const char *command) passes the command name or program name specified by command to the host environment to be executed by the command processor and returns after the command has been completed.

Declaration

Following is the declaration for system() function.

int system(const char *command)

Parameters

  • command − This is the C string containing the name of the requested variable.

This is very useful function to clear screen at run time of the program

rand():

The C library function int rand(void) returns a pseudo-random number in the range of 0 to RAND_MAX.

RAND_MAX is a constant whose default value may vary between implementations but it is granted to be at least 32767.

Features:

  • This project provides certain name as user by default and there a facility to create a new user too. You can enter your name as user.

  • In the project, you can view the total statistics.

  • The record option in the project is for displaying the data of user which has already used the application. you can view typing speed, accuracy.

  • If you want to terminate the program without any use, you can select exit option in the main menu.

Thank you