CHAT GPT VIBES : How I used C to make my program write text like chat gpt!

CHAT GPT VIBES : How I used C to make my program write text like chat gpt!

If you use chat gpt regularly or have even used it just once, you'd notice how it displays the answers to your questions. Chat gpt doesn't just "vomit" the answers to you all at once and say , "Bro there's the answer read it !!", kind of like the image below. Wherein the older woman signifies chat gpt and the little girl signifies you, the user.

Instead, it returns the text almost like you would if you were writing or typing. It does it sequentially, letter by letter and character by character.

I have always found that detail quite fascinating. So I created something similar. Inspired by a young lady in Nigeria(my country), who had just broken the world record for the longest time spent cooking, I created a program to write out a heartfelt message just like chat gpt would.

HOW DID I DO IT??

Step 1: I added the libraries I would be using, just like I would have in every other C program.

Adding my libraries

The reason why I used stdio. h in C is that this header file imports different variables, macros, and functions to perform input and output operations.

The reason why I used string.h header is because it defines one variable type, one macro, and various functions for manipulating arrays of characters.

As for unistd.h, The main purpose of unistd.h is to provide a set of standardized functions, constants, and types for interacting with the operating system. These functions allow you to perform various low-level operations related to input/output, process management, and other system-related tasks. Here are some key areas where unistd.h is commonly used:

  1. File Operations: unistd.h provides functions like open(), read(), write(), and close() that allow you to work with files. These functions enable you to open files, read or write data to them, and close them when you're done.

  2. Process Control: unistd.h includes functions like fork(), exec(), and exit() that facilitate process creation and management. For example, fork() allows you to create a new process, exec() helps replace the current process image with a new one, and exit() terminates the current process.

  3. System Calls: unistd.h also provides access to various system calls, which are functions that allow interaction with the operating system kernel. Examples of system calls include sleep(), getpid(), chdir(), and unlink(). These functions enable you to pause program execution, retrieve the process ID, change the current working directory, and delete files, respectively.

  4. Miscellaneous Functionality: Additionally, unistd.h includes functions for tasks such as terminal I/O (isatty(), ttyname()), getting system information (gethostname(), getpagesize()), and more.

By including unistd.h in your C program, you gain access to these functions and can utilize the underlying operating system's capabilities. These functions allow you to perform various operations, manage processes, interact with files, and access system-specific features, making your program more versatile and powerful.

You should by now be having an idea of where this is going. I hope you understood the first step!

Noticed I used char for message[]?? Well, you'll understand why in the next step!

step 3:
I created delay and set it to 50000.

putchar() is a function in the C programming language that writes a single character to the standard output stream, stdout.

fflush() function in C is used to flush the buffer of any stream and it prints the data of the buffer to the respective file. fflush() in C is defined in the <stdio. h>. fflush() function in C takes only a single parameter which is a pointer to the File Object in which we want to flush or write our data.
ussleep() is a C API that suspends the current process for the number of microseconds passed to it. It can be used for delaying a job.

And , That my dear reader, is how I made my program give off chat gpt vibes!!!

Check out this link to view the video of the implemented program!!

https://twitter.com/Golden_builds/status/1658056387161718785