<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fred Cheto on Medium]]></title>
        <description><![CDATA[Stories by Fred Cheto on Medium]]></description>
        <link>https://medium.com/@fredycheto?source=rss-36013b85ff6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M4YkOTfpb-wO0qJ-iKLy1w.jpeg</url>
            <title>Stories by Fred Cheto on Medium</title>
            <link>https://medium.com/@fredycheto?source=rss-36013b85ff6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:47:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fredycheto/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Beginner Guide to C File Handling]]></title>
            <link>https://medium.com/@fredycheto/a-beginner-guide-to-c-file-handling-fb5ea4a7bc5f?source=rss-36013b85ff6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb5ea4a7bc5f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[file-handling]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[binary]]></category>
            <dc:creator><![CDATA[Fred Cheto]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 05:31:53 GMT</pubDate>
            <atom:updated>2024-02-02T05:31:53.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-1AuB4Jv9f8ifoOiteO3w.jpeg" /><figcaption>Image Source: <a href="https://unsplash.com/photos/computer-programming-codes-displayed-on-a-monitor-MgtHZ4zlC1U">Marcus Spiske</a></figcaption></figure><p>File handling in C is a crucial programming aspect, allowing us to interact with external files, read and write data, and perform various operations.</p><p>Understanding file-handling operations is essential for any programmer, as it enables manipulating data stored in files, a common requirement in software development.</p><p>Now, let’s delve into the detailed guide on file operations using C language and explore the significance of these operations.</p><h3>ASCII Plain Text File Operations</h3><p>ASCII plain text files have a variety of functions for data manipulation.</p><p>These include:</p><ul><li>Functions for reading individual characters one at a time <strong>(getc() and putc()).</strong></li><li>Functions for handling formatted input and output (like fscanf() and fprintf()).</li><li>Functions for reading and writing single lines at a time (such as fgets() and fputs()).</li></ul><h3>Binary File Operations</h3><p>Binary files, which deal with raw bytes, present various scenarios for reading from and writing.</p><p>Unlike plain text (ASCII) files, where each set of bytes represents an ASCII character, binary files store raw bytes in any desired format.</p><p>The advantages of binary files over ASCII files include their typically smaller size and faster read and write operations (as there’s no need to convert between raw bytes and ASCII characters).</p><p>However, binary files have the drawback of being non-human-readable, meaning they cannot be opened in a text editor for visual inspection.</p><p>To handle binary data, the <strong>fread() and fwrite() </strong>functions come into play, allowing the reading and writing of raw bytes to and from binary files.</p><h3>File Handling Operations in C</h3><h4>1. Creating and Opening Files</h4><p>When interacting with files in C programming, fopen is the gateway, the bridge between your code and the external world of files.</p><p>It aims to open a file and establish a connection, allowing you to read from or write to it as needed.</p><p>To create and open a file in C, we use the `fopen` function, which takes the file name and mode as parameters. For example:</p><pre>FILE *filePointer; // Declare a file pointer<br><br>filePointer = fopen(&quot;example.txt&quot;, &quot;r&quot;); // Open the file for reading<br><br>// Perform operations on the file<br><br>fclose(filePointer); // Close the file stream</pre><p>In this example, fopen is used to open a file named “example.txt” in read mode (“r”).</p><p>The file pointer pointing to the first char is returned by fopen and is then used to perform operations on the file, such as reading its contents.</p><p>Opening a text file in write mode (“w”) will create a<strong> new </strong>or <strong>overwrite an existing file.</strong></p><p><strong>O</strong>pening a file in <strong>append mode (“a”)</strong> will position the file pointer at the end of the file for writing. If it doesn&#39;t exist, a new one is created.</p><p>Other modes include:</p><ul><li>ab: open for append in binary</li><li>ab+: open for both reading and appending in binary.</li><li>a+: searches the file, load it into memory and set up a pointer.</li><li>w+: search for files, if it exists, contents are overwritten.</li><li>wb+: open for both reading and writing, if file x, contents overwritten.</li><li>r+: open, load to memory, and set up a pointer to the first character.</li></ul><p><strong>Return:</strong> the<strong> file pointer</strong> on success, or <strong>null</strong> on failure.</p><h4>2. Closing Files</h4><p>After performing operations on a file, it’s essential to close it using the `fclose` function to release the resources associated with the file.</p><p>Its purpose is simple yet crucial: to close the file stream and release the associated resources, ensuring that the file is no longer accessible for reading or writing</p><pre>FILE *filePointer; // Declare a file pointer<br><br>filePointer = fopen(&quot;example.txt&quot;, &quot;r&quot;); // Open the file for reading<br><br>// Perform operations on the file<br><br>fclose(filePointer); // Close the file stream</pre><p>As you can see, after opening a file using fopen and performing various operations, it’s essential to close the file using fclose to release its resources.</p><p>This ensures the file is properly closed and any system resources, such as memory or file descriptors, are freed up.</p><p>The usage of fclose is vital for efficient resource management in C <a href="https://medium.com/@fredycheto/uncovering-the-basics-of-shell-programming-edcafea10192">programming</a>.</p><p>Failing to close files after use can lead to resource leaks and potential issues with file access.</p><p>Therefore, it’s good practice to pair file-opening operations with corresponding fclose calls to maintain a clean and efficient file-handling process.</p><h4>3. Reading From and Writing To Files</h4><p>Ah, the quartet of file handling functions — <strong>fread, fwrite, fscanf, and fprintf!</strong></p><p>These functions are the maestros of data transfer between your <a href="https://medium.com/@fredycheto/unleashing-c-programming-dive-deep-into-linked-lists-1330d5c3015a">C program</a> and external files, orchestrating the symphony of reading and writing with precision and finesse.</p><p>Let’s explore each of them with appropriate code snippets to illuminate their roles in the grand performance of file handling.</p><ul><li><strong>fread:</strong></li></ul><p>The fread function takes four main arguments: a <strong>pointer</strong> to the <strong>memory location</strong> where the data will be stored, the<strong> size of each element</strong> to be read, the <strong>number of elements to read</strong>, and the <strong>file pointer</strong>.</p><p>Here’s a snippet to showcase its usage:</p><pre>     FILE *filePointer;<br><br>     int data[5]; // Array to store the read data<br><br>     filePointer = fopen(&quot;data.bin&quot;, &quot;rb&quot;); // Open the binary file for reading<br><br>     fread(data, sizeof(int), 5, filePointer); // Read 5 integers from the file<br><br>     fclose(filePointer); // Close the file stream</pre><ul><li><strong>fwrite:</strong></li></ul><p><strong>fwrite</strong> writes data to a file. It requires four main arguments: a pointer to the data to be written, the size of each element, the number of elements, and the file pointer.</p><p>Here’s a snippet to demonstrate its prowess:</p><pre>     FILE *filePointer;<br>     int data[5] = {1, 2, 3, 4, 5}; // Data to be written<br><br>     filePointer = fopen(&quot;output.bin&quot;, &quot;wb&quot;); // Open a binary file for writing<br><br>     fwrite(data, sizeof(int), 5, filePointer); // Write 5 integers to the file<br><br>     fclose(filePointer); // Close the file stream</pre><ul><li><strong>fscanf:</strong></li></ul><p>The <strong>fscanf</strong> function excels at <strong>reading formatted data from a file</strong>, using a format string to specify the expected data types. Here’s a snippet to showcase its performance:</p><pre>     FILE *filePointer;<br><br>     int num1, num2;<br><br>     filePointer = fopen(&quot;input.txt&quot;, &quot;r&quot;); // Open the text file for reading<br><br>     fscanf(filePointer, &quot;%d %d&quot;, &amp;num1, &amp;num2); // Read two integers from the file<br><br>     fclose(filePointer); // Close the file stream</pre><ul><li><strong>fprintf:</strong></li></ul><p>Last, we have the virtuoso of formatted output —<strong> fprintf</strong>! This function shines in writing formatted data to a file, using a <strong>format string</strong> to specify the output structure.</p><p>Here’s a snippet to highlight its usage:</p><pre>     FILE *filePointer;<br><br>     int num1 = 10, num2 = 20;<br><br>     filePointer = fopen(&quot;output.txt&quot;, &quot;w&quot;); // Open a text file for writing<br><br>     fprintf(filePointer, &quot;The numbers are: %d and %d\n&quot;, num1, num2); // Write formatted output to the file<br><br>     fclose(filePointer); // Close the file stream</pre><h4>4. Moving within Files</h4><p>The `fseek` function is used to move the file pointer to a specific location within the file, while `ftell` returns the current position of the file pointer.</p><h4><strong>5. Deleting and Renaming Files</strong></h4><p>Files can be deleted using the `remove` function and renamed using the `rename` function.</p><h4>6. Error Handling in File Operations</h4><p>Error handling in file operations involves checking for errors using functions like `ferror` and `feof` to handle exceptional conditions during file operations.</p><h3>Understanding File Descriptors</h3><p>In C programming, file descriptors are integer values that uniquely identify an open file in the operating system. The three standard file descriptors are:</p><ol><li><strong>Standard Input (stdin):</strong> This file descriptor (0) is associated with the standard input stream and is typically used for reading input from the user.</li><li><strong>Standard Output (stdout):</strong> This file descriptor (1) is associated with the standard output stream and is used for writing normal output.</li><li><strong>Standard Error (stderr): </strong>This file descriptor (2) is associated with the standard error stream and is used for writing error messages.</li></ol><p>These file descriptors play a crucial role in input/output operations and are essential for understanding the data flow within a program.</p><h3>System Calls and File Permissions</h3><p>System calls such as `open,` `close,` `read,` and `write` are fundamental functions for file I/O operations in C.</p><p>These system calls provide the necessary mechanisms to interact with files at the system level, allowing for low-level file data manipulation.</p><p>When creating a file using the `open` system call, file permissions can be set using flags such as `O_RDONLY,` `O_WRONLY,` and `O_RDWR` to specify read-only, write-only, or read-write access, respectively.</p><h3>Understanding the Difference Between a Function and a System Call</h3><p>While functions are routines that can be called within a program, system calls are a program&#39;s request to the operating system for low-level operations, such as file I/O.</p><h3>Frequently Asked Questions</h3><h4>Who Designed and Implemented the Original Unix Operating System?</h4><p>Ken Thompson, Dennis Ritchie, and others at Bell Labs designed and implemented the original Unix operating system in the late 1960s and early 1970s.</p><p>Ken Thompson and Dennis Ritchie wrote the first version of the Unix shell, the command-line interpreter for Unix-like systems.</p><h4>Who Invented the B Programming Language (The Direct Predecessor to the C Programming Language)?</h4><p>Now, when it comes to the B programming language, Ken Thompson invented it.</p><p>B was a precursor to the C programming language, which Thompson and Ritchie also developed.</p><p>The C language, as we know it, became one of the world&#39;s most widely used programming languages.</p><h4>How Does a Shell Work?</h4><p>A shell is a command-line interpreter that takes commands from the user and executes them.</p><p>It allows users to interact with the operating system by entering commands.</p><p>The shell interprets these commands and then communicates with the operating system to carry them out.</p><h4>What Is a Pid and A Ppid?</h4><p>A PID, or process ID, is a unique identifier assigned to each process in a Unix-like operating system.</p><p>The operating system uses it to track and manage processes. The PPID, or parent process ID, identifies the parent process of a given process.</p><p>It’s essential for process management and control.</p><h4>How Do You Manipulate the Environment of the Current Process?</h4><p>To manipulate the current process&#39;s environment, you can use environment variables. These variables hold information such as the path to executable files, user preferences, and system configuration.</p><p>By manipulating these variables, you can affect how the current process behaves and interacts with the system.</p><h4>How can You Create Processes in Linux?</h4><p>Creating processes in a Unix-like operating system involves using system calls such as fork() and exec().</p><p>The fork() system call creates a new process, an exact copy of the calling process. The exec() system call replaces the current process with a new program.</p><h4>What Are the Three Prototypes Of Main?</h4><p>The three prototypes of main in C programming are <strong>int main(), int main(int argc, char *argv[])</strong>, and <strong>int main(int argc, char *argv[], char *envp[]).</strong></p><p>These different prototypes allow for variations in how command-line arguments and environment variables are handled by the main function.</p><h4>How Does the Shell Use the Path to Find the Programs?</h4><p>The shell uses the PATH environment variable to find programs. When a user enters a command, the shell searches through the directories listed in the PATH variable to locate the executable file associated with the command.</p><h4>How Do You Execute Another Program With the Execve System Call?</h4><p>To execute another program with the execve system call, you provide the path to the executable file and an array of arguments to be passed to the new program.</p><p>The execve system call replaces the current process image with a new one, effectively running the specified program.</p><ul><li>How to suspend the execution of a process until one of its children terminates</li></ul><p>Suspending the execution of a process until one of its children terminates can be achieved using the wait() system call.</p><p>This call causes the parent process to block until a child process terminates, allowing for synchronization and coordination between processes.</p><h4>What is EOF / “end-of-file”?</h4><p>Finally, EOF, or “end-of-file,” is a condition in a computer operating system where no more data can be read from a data source. It’s commonly used to indicate the end of input when reading from a file or a data stream.</p><p>In conclusion, mastering file-handling operations in C is essential for any programmer. File-handling operations are fundamental to software development, from creating and opening files to reading, writing, and manipulating data.</p><p>Understanding file descriptors, system calls, and file permissions provides a comprehensive understanding of file I/O in C programming.</p><p>So, there you have it — a practical guide to C file handling. I hope this overview has shed some light on the intricacies of file operations in C programming.</p><p>Remember, file handling is a fundamental aspect of programming, and mastering it will open up a world of possibilities in software development.</p><p>If you love this piece, comment, like, and subscribe. Feel free to reach out on <a href="https://twitter.com/_Cheto02">Twitter</a>, <a href="http://www.linkedin.com/in/fred-c-8b6483194">Linkedin</a>, and <a href="https://t.co/LgrcwP75rR">GitHub</a>. Happy coding!</p><p>Reference</p><ol><li><a href="https://www.geeksforgeeks.org/basics-file-handling-c/?ref=header_search">https://www.geeksforgeeks.org/basics-file-handling-c/?ref=header_search</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb5ea4a7bc5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unleashing C Programming: A Beginners Guide to Linked Lists]]></title>
            <link>https://medium.com/@fredycheto/unleashing-c-programming-dive-deep-into-linked-lists-1330d5c3015a?source=rss-36013b85ff6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1330d5c3015a</guid>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Fred Cheto]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 05:46:56 GMT</pubDate>
            <atom:updated>2024-01-26T23:25:34.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xb3uTk2semoFJCDFzp7AuA.jpeg" /></figure><p>Have you ever felt the thrill of solving a dynamic puzzle where each piece adapts and changes? That’s the wonder of linked lists. Let us step into this dynamic realm and help you elevate your coding game!</p><h3>What are Linked Lists? (In Simple Terms)</h3><p>Imagine a necklace. Each gem (our <strong>data</strong>) is connected by a chain (a <strong>pointer</strong>). Unlike rigid boxes (<strong>arrays</strong>), these gems can easily be added or removed.</p><p>That’s the essence of linked lists — a flexible and efficient way to store information.</p><h3>Types of Linked Lists You Should Know</h3><ol><li>Singly Linked Lists: A one-directional path; you move forward, one step at a time.</li><li>Doubly Linked Lists: A two-way street; move forward or rewind as you like.</li><li>Circular Linked Lists: A loop; think of a race track where you can keep running laps.</li></ol><p>Python Language Implementation of Linked Lists</p><pre>class Node:<br>    def __init__(self, data=None):<br>        self.data = data<br>        self.next = None<br>class LinkedList:<br>    def __init__(self):<br>        self.head = None<br>    def insert(self, data):<br>        if not self.head:<br>            self.head = Node(data)<br>        else:<br>            cur = self.head<br>            while cur.next:<br>                cur = cur.next<br>            cur.next = Node(data)<br>    def display(self):<br>        cur = self.head<br>        while cur:<br>            print(cur.data, end=&#39; &#39;)<br>            cur = cur.next<br>       print()</pre><p>C Language Implementation of Linked Lists</p><pre><br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>// Define the node structure<br>typedef struct Node {<br>  int data;<br>  struct Node *next;<br>} Node;<br>// Function to create a new node<br>Node *create_node(int data) {<br>  Node *new_node = (Node *)malloc(sizeof(Node));<br>  if (!new_node) {<br>    printf(&quot;Error allocating memory for node.\n&quot;);<br>    exit(1);<br>  }<br>  new_node-&gt;data = data;<br>  new_node-&gt;next = NULL;<br>  return new_node;<br>}<br>// Function to insert a node at the head of the list<br>void insert_at_head(Node **head, int data) {<br>  Node *new_node = create_node(data);<br>  new_node-&gt;next = *head;<br>  *head = new_node;<br>}<br>// Function to print the contents of the list<br>void print_list(Node *head) {<br>  Node *current = head;<br>  printf(&quot;List: &quot;);<br>  while (current) {<br>    printf(&quot;%d -&gt; &quot;, current-&gt;data);<br>    current = current-&gt;next;<br>  }<br>  printf(&quot;NULL\n&quot;);<br>}<br>// Function to free the memory used by the list<br>void free_list(Node *head) {<br>  Node *current = head;<br>  Node *next;<br>  while (current) {<br>    next = current-&gt;next;<br>    free(current);<br>    current = next;<br>  }<br>}<br>int main() {<br>  Node *head = NULL; // Empty list<br>  // Insert some nodes<br>  insert_at_head(&amp;head, 10);<br>  insert_at_head(&amp;head, 20);<br>  insert_at_head(&amp;head, 30);<br>  // Print the list<br>  print_list(head);<br>  // Free the memory used by the list<br>  free_list(head);<br>  return 0;<br>}</pre><h3>Why Are Linked Lists a Big Deal?</h3><ul><li><strong>Adaptability: </strong>They reshape as per our needs.</li><li><strong>Speedy Operations: </strong>Quick additions or removals.</li><li><strong>Smart Memory Use: </strong>Uses precisely what’s needed — no wastage.</li></ul><h3>But… Are There Challenges?</h3><p><strong>⚠️ Traversal Time: </strong>Jumping straight to a gem might take longer.</p><p><strong>⚠️ Memory Factor: </strong>Those connecting chains (pointers) need space.</p><p><strong>⚠️ Learning Curve: </strong>A tad trickier than our regular boxes (arrays).</p><h3>Where You’ll See Linked Lists</h3><p>They’re the unsung heroes — powering playlists, games, and your browser’s history. They’re like the backstage tech crew in a concert, making everything run smoothly.</p><h3>Parting Code</h3><p>In the tech world of programming, linked lists are the silent game-changers. Now that you’ve had this quick tour, you’re ready to harness their power. So, code on, adapt, and let linked lists elevate your projects.</p><p>Ready, set, code! If you loved this article, like, comment, bookmark, and connect with me on <a href="https://github.com/Cheto02">github</a>, <a href="http://www.linkedin.com/in/fred-c-8b6483194">Linkedin</a>, and <a href="https://twitter.com/_Cheto02">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1330d5c3015a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Rise of Python: Past, Present, and Future]]></title>
            <link>https://medium.com/@fredycheto/the-rise-of-python-past-present-and-future-a7d327689d29?source=rss-36013b85ff6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7d327689d29</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Fred Cheto]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 11:22:30 GMT</pubDate>
            <atom:updated>2024-03-11T12:21:52.782Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MiAyRDE-XdFuzVJX" /><figcaption>Photo by <a href="https://unsplash.com/@cdr6934?utm_source=medium&amp;utm_medium=referral">Chris Ried</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Python, often referred to as the Swiss Army knife of programming languages, is not just a language; it’s a phenomenon. It has transformed the world of software development and continues to shape the future.</p><p>In this blog post, I’ll take you on a journey through the evolution of Python, its current status, its future trajectory, and its profound impact on the tech world.</p><h3>Python’s Evolution: From Humble Beginnings to Prominence</h3><p>Imagine Python as a journey, a story that started back in the late ’80s with <strong>Guido van Rossum</strong>, Python’s creator, who envisioned a language that emphasizes code readability.</p><p>Python is like a language that adapts to your style and not vice versa. Its simplicity, combined with an elegant syntax, made it a hit among developers.</p><p>In Python’s early days, it was like a startup, modest and experimental. But it soon became the “Unicorn” of programming languages.</p><p>With the introduction of Python 2.0, it gained robustness and momentum. The community grew, and many libraries and frameworks emerged, solidifying Python’s position as a top-tier language.</p><h3>Python’s Present: A Dominant Force in Tech</h3><p>Today, Python is everywhere, from web development to data science, machine learning, and more.</p><p>It’s like the foundation of a skyscraper, supporting and enabling various technological marvels. One of the driving forces behind Python’s success is its versatility.</p><p>Python can help you build web applications with frameworks like <strong>Django</strong> and <strong>Flask.</strong></p><p>It also supports data analysis with Pandas and machine learning with <a href="https://www.bing.com/ck/a?!&amp;&amp;p=962081096f340abbJmltdHM9MTY5NzQxNDQwMCZpZ3VpZD0zMzZkYWYwOS05ODdlLTZjZDUtMjE1Ny1iZDM3OTk4MjZkOWMmaW5zaWQ9NTIxNA&amp;ptn=3&amp;hsh=3&amp;fclid=336daf09-987e-6cd5-2157-bd3799826d9c&amp;psq=tensorflow&amp;u=a1aHR0cHM6Ly93d3cudGVuc29yZmxvdy5vcmcv&amp;ntb=1"><strong>TensorFlow</strong></a> and <strong>PyTorch</strong>.</p><p>It’s like having a single tool that can fix your car, cook your dinner, and do your taxes.</p><p>The simplicity of Python’s syntax makes it incredibly accessible to beginners. It’s like teaching someone to ride a bicycle on a smooth, wide road. You can learn the basics quickly, but there’s always more to explore.</p><h3>Python’s Future: Expanding Horizons and Opportunities</h3><p>Python’s journey doesn’t end here; it’s more like a rocket just leaving the launchpad.</p><p>The language is evolving at a remarkable pace. When this article was published, a newer Python 3.120 resolved some legacy issues and gained massively performance wise.</p><p>Python’s future is closely linked to the emerging AI and machine learning fields. Libraries like <strong>Scikit-Learn, TensorFlow, and </strong><a href="https://www.bing.com/ck/a?!&amp;&amp;p=6a0c45685008f366JmltdHM9MTY5NzQxNDQwMCZpZ3VpZD0zMzZkYWYwOS05ODdlLTZjZDUtMjE1Ny1iZDM3OTk4MjZkOWMmaW5zaWQ9NTIxOA&amp;ptn=3&amp;hsh=3&amp;fclid=336daf09-987e-6cd5-2157-bd3799826d9c&amp;psq=PYTORCH&amp;u=a1aHR0cHM6Ly9weXRvcmNoLm9yZy8&amp;ntb=1"><strong>PyTorch</strong></a> have made it the go-to language for data scientists and AI engineers.</p><p>One of the most exciting developments is WebAssembly. Python aims to extend its influence on web development through projects like <a href="https://brython.info/">Brython</a> and <a href="https://www.bing.com/ck/a?!&amp;&amp;p=a86d69bb8bb4707eJmltdHM9MTY5NzQxNDQwMCZpZ3VpZD0zMzZkYWYwOS05ODdlLTZjZDUtMjE1Ny1iZDM3OTk4MjZkOWMmaW5zaWQ9NTE5Ng&amp;ptn=3&amp;hsh=3&amp;fclid=336daf09-987e-6cd5-2157-bd3799826d9c&amp;psq=pyodide&amp;u=a1aHR0cHM6Ly9weW9kaWRlLm9yZy8&amp;ntb=1">Pyodide</a>.</p><p>Think of it as Python packing its bags for a new adventure in the web development world. It opens doors to deploying web applications with Python in <a href="https://www.linkedin.com/posts/fred-c-8b6483194_tipsandtricks-googlechrome-memoryusage-activity-7096411313358217216-Kutw?utm_source=share&amp;utm_medium=member_desktop">browsers!</a></p><h3>The Impact of Python: Where Do You Fit In?</h3><p>So, what’s in it for you? Python isn’t just a language; it’s a gateway to many opportunities.</p><ol><li><strong>Career Growth: </strong>Python developers are in high demand. Learning Python can open doors to exciting career prospects. The demand for data scientists and machine learning engineers with Python skills is skyrocketing.</li><li><strong>Community: </strong>The Python community is supportive and vibrant. You’ll have access to many resources, from documentation to online courses and forums. It’s like joining a big, friendly tech family.</li><li><strong>Learning Curve:</strong> Python’s gentle learning curve is perfect for beginners. It’s like learning to swim in a calm, clear lake, with experienced swimmers ready to help you every step of the way.</li><li><strong>Innovation: </strong>Python is a hub of innovation. With Python, you can contribute to groundbreaking projects, from self-driving cars to cancer research.</li></ol><h3>Connect and Share</h3><p>If Python has piqued your interest, connect with me on <a href="http://www.linkedin.com/in/%20fred-c-8b6483194">LinkedIn</a> and <a href="https://twitter.com/_Cheto02">Twitter/X</a>. Let’s dive into the world of Python together.</p><p>Whether you’re just starting your journey in tech or an experienced developer, Python has something to offer you. If you found this information helpful, consider sharing it with your network.</p><p>Python’s influence will only grow, and being part of this dynamic community is exciting. Let’s make the most of it together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7d327689d29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Programmer’s Rite of Passage: Master Array Sorting in C and Python to Unlock Your Full…]]></title>
            <link>https://medium.com/@fredycheto/the-programmers-rite-of-passage-master-array-sorting-in-c-and-python-to-unlock-your-full-e9866e9c8c44?source=rss-36013b85ff6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9866e9c8c44</guid>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Fred Cheto]]></dc:creator>
            <pubDate>Thu, 14 Dec 2023 05:32:06 GMT</pubDate>
            <atom:updated>2024-02-02T21:11:13.089Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Programmer’s Rite of Passage: Master Array Sorting in C and Python to Unlock Your Full Potential (For Beginners)</h3><p>The Backend landscape is majestic, where data dances and algorithms whisper instructions. But within this orchestra of code, a crucial skill reigns supreme: array sorting.</p><p>Taming chaotic data into elegant order isn’t just a programmer’s checkbox; it’s a gateway to unlocking your potential.</p><p>Imagine a bustling marketplace, merchants hawking wares in no discernible order. Finding that perfect spice? It’s a frustrating quest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZmIy5jxUBUu8Y30bzyGNcg.jpeg" /></figure><h3>The Most Common Array Sorting Algorithms in C Programming</h3><p>Array sorting is a diverse area, with newer methods coming up every few years.</p><p>Here is my list of the most commonly used sorting methods in C and <a href="https://www.linkedin.com/posts/fred-c-8b6483194_pythonprogramming-pythonlanguage-programmingjourney-activity-7119645665831350272-ahIm?utm_source=share&amp;utm_medium=member_desktop">Python</a>:</p><h4>1. Bubble Sort Algorithm</h4><p>Bubble sort is a simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order.</p><p>Bubble sort, the gentle giant, waltzes through each element, nudging them into place like a librarian meticulously arranging books.</p><p>Here is its simple yet powerful code:</p><p><strong>C</strong></p><pre>#include &lt;stdio.h&gt;<br><br>void sort(int array[], int size)<br>{<br>    for(int i = 0; i &lt; size - 1; i++)<br>    {<br>        for(int j = 0; j &lt; size - i - 1; j++)<br>        {<br>            if(array[j] &gt; array[j+1])//For Descending order, use &lt;<br>            {<br>                int temp = array[j];//create a temporary array to help swap j and j+1<br>                array[j] = array[j+1];<br>                array[j+1] = temp;<br>            }<br>        }<br>    }<br><br><br>void printArray(int array[], int size)<br>{<br>    for(int i = 0; i &lt; size; i++)<br>    {<br>        printf(&quot;%d &quot;, array[i]);<br>    }<br>    printf(&quot;\n&quot;);<br>}<br><br><br>int main()<br>{<br>    int array[] = {3, 8, 4, 9, 5, 7};<br>    int size = sizeof(array)/sizeof(array[0]);<br>    sort(array, size);<br>    printArray(array, size);<br>    return 0;<br>}<br>}</pre><p><strong>Python</strong></p><pre>def bubble_sort(data):<br>  for i in range(len(data) - 1):<br>    for j in range(len(data) - i - 1):<br>      if data[j] &gt; data[j + 1]:<br>        data[j], data[j + 1] = data[j + 1], data[j]<br>  return data</pre><p>Here’s an example of how bubble sort works:<br>Consider the array: <strong>{3, 8, 4, 9, 5, 7}</strong></p><p><strong>Pass 1:<br>3 4 8 5 7 9</strong></p><p><strong>Pass 2:<br>3 4 5 7 8 9</strong></p><p><strong>Pass 3:<br>3 4 5 7 8 9</strong></p><p>The algorithm traverses the array from left to right and compares adjacent elements.</p><p>The two elements are swapped if the left element exceeds the right element.</p><p>This process is repeated until the array is sorted.</p><p><strong>Inside the Nested Loop</strong></p><p>The outer loop, controlled by the variable <strong>i</strong>, goes through the array from the beginning to the<strong> second-to-last element(</strong>for(int i = 0; i &lt; size — 1; i++)).</p><p>The reason we stop at the second-to-last element in the outer loop (i &lt; size — 1) is because when we’re comparing array[j] with array[j+1] inside the inner loop, we don’t need to compare the last element with anything.</p><p>By the time the outer loop reaches the second-to-last element, the largest element has already <strong>bubbled up</strong> to its correct position at the end of the array through the swapping process in the inner loop.</p><p>So, there’s no need to compare the last element with anything, as it’s already in its correct place.</p><p>The inner loop, controlled by the variable <strong>j</strong>, goes through the array to compare elements and perform the swapping.</p><p>Now, the reason it goes from the beginning to (<strong>size -i -1)</strong> is to avoid unnecessary comparisons.</p><p>As the outer loop progresses and the variable <strong>i</strong> increases, the largest <strong>i</strong> elements in the array are already in their correct positions.</p><p>So, in the inner loop, we don’t need to compare the elements already in their correct positions.</p><p>That’s why we limit the range of the inner loop by subtracting i from the total size of the array and then subtracting 1 more to ensure we don’t go out of bounds.</p><p>The if statement inside the inner loop is where the magic happens. It compares adjacent elements of the array.</p><p>If the current element is greater than the next one, it swaps them. This process continues, bubbling up the largest element to its correct position in the array during each pass of the outer loop.</p><p>The sorted array is <strong>{3, 4, 5, 7, 8, 9}</strong>. Is Bubble Sort considered the best sorting technique in Python? It’s not the most efficient sorting algorithm, but it’s a great way to <a href="https://www.linkedin.com/posts/fred-c-8b6483194_uncovering-the-basics-of-shell-programming-activity-7139912601735454720-vfJC?utm_source=share&amp;utm_medium=member_desktop">understand the basics</a> of sorting. Plus, it’s fun to say “bubble sort”! Go ahead, give it a try. Bubble sort!</p><h4><strong>2. Merge Sort Algorithm</strong></h4><p>As you ascend the coding ladder, faster, more intricate algorithms emerge.</p><p>Merge sort, the divide-and-conquer maestro, partitions arrays like a chef slicing dough, then merges them back into harmonious order.</p><p>This method splits the array into smaller parts repeatedly until each part contains only one element.</p><p>Afterward, it combines the sorted smaller parts in a manner that guarantees the entire array is sorted.</p><p>With a time complexity of <strong>O(n log n)</strong>, it’s much speedier than comparison sorts when dealing with large sets of data.</p><pre>#include &lt;stdio.h&gt;<br><br>void merge(int arr[], int left, int mid, int right) {<br>    int i, j, k;<br>    int n1 = mid - left + 1;<br>    int n2 = right - mid;<br><br>    int L[n1], R[n2];<br><br>      for (i = 0; i &lt; n1; i++)<br>        L[i] = arr[left + i];<br>      for (j = 0; j &lt; n2; j++)<br>        R[j] = arr[mid + 1 + j];<br><br>    i = 0;<br>    j = 0;<br>    k = left;<br>    while (i &lt; n1 &amp;&amp; j &lt; n2) {<br>        if (L[i] &lt;= R[j]) {<br>            arr[k] = L[i];<br>            i++;<br>        } else {<br>            arr[k] = R[j];<br>            j++;<br>        }<br>        k++;<br>    }<br><br>    while (i &lt; n1) {<br>        arr[k] = L[i];<br>        i++;<br>        k++;<br>    }<br><br>    while (j &lt; n2) {<br>        arr[k] = R[j];<br>        j++;<br>        k++;<br>    }<br>}<br><br>void mergeSort(int arr[], int left, int right) {<br>    if (left &lt; right) {<br>        int mid = left + (right - left) / 2;<br><br>        mergeSort(arr, left, mid);<br>        mergeSort(arr, mid + 1, right);<br><br>        merge(arr, left, mid, right);<br>    }<br>}<br><br>int main() {<br>    int arr[] = {12, 11, 13, 5, 6, 7};<br>    int arr_size = sizeof(arr) / sizeof(arr[0]);<br><br>    mergeSort(arr, 0, arr_size - 1);<br><br>    printf(&quot;Sorted array: \n&quot;);<br>    for (int i = 0; i &lt; arr_size; i++)<br>        printf(&quot;%d &quot;, arr[i]);<br>    printf(&quot;\n&quot;);<br><br>    return 0;<br>}</pre><pre><br>def merge_sort(arr):<br>    if len(arr) &gt; 1:<br>        mid = len(arr) // 2<br>        L = arr[:mid]<br>        R = arr[mid:]<br><br>        merge_sort(L)<br>        merge_sort(R)<br><br>        i = j = k = 0<br><br>        while i &lt; len(L) and j &lt; len(R):<br>            if L[i] &lt; R[j]:<br>                arr[k] = L[i]<br>                i += 1<br>            else:<br>                arr[k] = R[j]<br>                j += 1<br>            k += 1<br><br>        while i &lt; len(L):<br>            arr[k] = L[i]<br>            i += 1<br>            k += 1<br><br>        while j &lt; len(R):<br>            arr[k] = R[j]<br>            j += 1<br>            k += 1<br><br>def main():<br>    arr = [12, 11, 13, 5, 6, 7]<br>    merge_sort(arr)<br>    print(&quot;Sorted array:&quot;, arr)<br><br>if __name__ == &quot;__main__&quot;:<br>    main()<br><br></pre><p>In both C and Python, the merge sort algorithm follows the same fundamental principles of dividing the array into smaller parts, sorting them, and then merging them back together.</p><p>The recursive nature of the algorithm allows for elegant and efficient sorting of large datasets, making it a powerful tool in the world of sorting algorithms.</p><h4><strong>3. Selection Sort</strong></h4><p>Ah, selection sort, a classic sorting algorithm that’s both simple and instructive.</p><p>In C, selection sort is a straightforward algorithm for sorting an array.</p><p>The idea is to repeatedly find the minimum element from the unsorted part of the array and swap it with the first unsorted element.</p><p>This process gradually builds up the sorted portion of the array at the beginning.</p><p>Here’s a simple implementation of selection sort in C:</p><pre>void selectionSort(int arr[], int n) {<br>    int i, j, minIndex, temp;<br>    for (i = 0; i &lt; n-1; i++) {<br>        minIndex = i;<br>        for (j = i+1; j &lt; n; j++) {<br>            if (arr[j] &lt; arr[minIndex]) {<br>                minIndex = j;<br>            }<br>        }<br>        temp = arr[minIndex];<br>        arr[minIndex] = arr[i];<br>        arr[i] = temp;<br>    }<br>}</pre><p>In the above C implementation, we use two nested loops.</p><p>The outer loop iterates through the array, and the inner loop finds the minimum element in the unsorted part of the array.</p><p>Once the minimum element is found, it’s swapped with the first unsorted element, effectively expanding the sorted portion of the array.</p><p>In <strong>Python, </strong>we can implement selection sort more concisely due to the language’s high-level constructs.</p><p>In this Python implementation, we use an approach similar to the C version.</p><p>We iterate through the array, find the minimum element in the unsorted part, and swap it with the first unsorted element.</p><p>Here’s a simple implementation of selection sort in Python:</p><pre>def selection_sort(arr):<br>    n = len(arr)<br>    for i in range(n-1):<br>        min_index = i<br>        for j in range(i+1, n):<br>            if arr[j] &lt; arr[min_index]:<br>                min_index = j<br>        arr[i], arr[min_index] = arr[min_index], arr[i]</pre><p>Selection sort is not the most efficient sorting algorithm, especially for large datasets, due to its time complexity of <strong>O(n²)</strong>.</p><p>However, it’s a great algorithm for educational purposes and for understanding the basics of sorting.</p><h4>4. The Quick Sort Algorithm</h4><p>In C, the quicksort algorithm is often implemented using pointers to manipulate array elements efficiently.</p><p>The algorithm follows a divide-and-conquer approach, where it selects a “pivot” element from the array and partitions the other elements into two sub-arrays according to whether they are less than or greater than the pivot.</p><p>This process is repeated recursively for each sub-array until the entire array is sorted.</p><p>In both C and Python, the quicksort algorithm exhibits a time complexity of O(n log n) on average, making it significantly faster than many other sorting algorithms for large datasets.</p><pre>void swap(int* a, int* b) {<br>    int t = *a;<br>    *a = *b;<br>    *b = t;<br>}<br><br>int partition(int arr[], int low, int high) {<br>    int pivot = arr[high];<br>    int i = (low - 1);<br><br>    for (int j = low; j &lt;= high - 1; j++) {<br>        if (arr[j] &lt; pivot) {<br>            i++;<br>            swap(&amp;arr[i], &amp;arr[j]);<br>        }<br>    }<br>    swap(&amp;arr[i + 1], &amp;arr[high]);<br>    return (i + 1);<br>}<br><br>void quickSort(int arr[], int low, int high) {<br>    if (low &lt; high) {<br>        int pi = partition(arr, low, high);<br>        quickSort(arr, low, pi - 1);<br>        quickSort(arr, pi + 1, high);<br>    }<br>}</pre><p>In <strong>Python</strong>, the quicksort algorithm can be implemented using a more concise and expressive syntax.</p><p>Python’s high-level abstractions make the implementation straightforward and elegant.</p><p>Here’s a simplified version of the quicksort algorithm in Python:</p><pre>def partition(arr, low, high):<br>    pivot = arr[high]<br>    i = low - 1<br><br>    for j in range(low, high):<br>        if arr[j] &lt; pivot:<br>            i += 1<br>            arr[i], arr[j] = arr[j], arr[i]<br><br>    arr[i + 1], arr[high] = arr[high], arr[i + 1]<br>    return i + 1<br><br>def quickSort(arr, low, high):<br>    if low &lt; high:<br>        pi = partition(arr, low, high)<br>        quickSort(arr, low, pi - 1)<br>        quickSort(arr, pi + 1, high)</pre><p>Its simplicity and efficiency have made it a favorite among programmers and computer scientists alike.</p><p>So, whether you’re manipulating pointers in C or harnessing Python’s expressive power, the quicksort algorithm stands as a testament to the beauty of efficient sorting methods.</p><h4>5. Insertion Sort Algorithm</h4><p>In C, the insertion sort algorithm works by building a sorted array one element at a time.</p><p>It’s like sorting a hand of cards by picking up one card at a time and inserting it into its correct position among the already sorted cards.</p><p>Here’s a <a href="https://medium.com/@fredycheto/uncovering-the-basics-of-shell-programming-edcafea10192?source=user_profile---------0----------------------------">basic implementation</a> of the insertion sort algorithm in C:</p><pre>void insertionSort(int arr[], int n) {<br>    int i, key, j;<br>    for (i = 1; i &lt; n; i++) {<br>        key = arr[i];<br>        j = i - 1;<br><br>        while (j &gt;= 0 &amp;&amp; arr[j] &gt; key) {<br>            arr[j + 1] = arr[j];<br>            j = j - 1;<br>        }<br>        arr[j + 1] = key;<br>    }<br>}</pre><p>In this C implementation, we start with the second element of the array (index 1) and compare it with the elements before it.</p><p>If the current element is smaller, we shift the larger elements one position to the right to make space for the current element.</p><p>We repeat this process until the entire array is sorted.</p><p>The insertion sort algorithm in <strong>Python</strong> follows the same principle of building a sorted array one element at a time. In this Python implementation, we iterate through the array, starting from the second element, and compare it with the elements before it.</p><p>If the current element is smaller, we shift the larger elements one position to the right to make space for the current element. We continue this process until the entire array is sorted. <strong>Here’s a simple implementation of the insertion sort algorithm in Python:</strong></p><pre>def insertionSort(arr):<br>    for i in range(1, len(arr)):<br>        key = arr[i]<br>        j = i - 1<br>        while j &gt;= 0 and key &lt; arr[j]:<br>            arr[j + 1] = arr[j]<br>            j -= 1<br>        arr[j + 1] = key</pre><p>Both the C and Python implementations of the insertion sort algorithm share the same core idea of gradually building a sorted array by inserting elements into their correct positions. It’s a fundamental sorting algorithm that’s easy to understand and implement in various <a href="https://www.linkedin.com/feed/update/urn:li:activity:7111937370928689152?utm_source=share&amp;utm_medium=member_desktop">programming</a> languages.</p><h3>Honorable Mentions</h3><p>Alongside quicksort, several other notable sorting algorithms have earned their place in the spotlight in both C and Python.</p><p>A notable mention in C is the<strong> “heap sort” algorithm</strong>. It leverages the structure of a binary heap to sort the array in place, exhibiting an <strong>O(n log n) </strong>time complexity.</p><p>Its in-place nature and lack of recursive calls make it an efficient and practical choice for sorting arrays in memory-constrained environments.</p><p><strong>Radix Sort </strong>is an algorithm that arranges elements by their digits. It goes through the array multiple times, organizing the elements according to the digit’s position at each pass.</p><p>The time complexity of Radix Sort is <strong>O(n * d)</strong>, where d represents the number of digits in the largest element. However, for small datasets, it may not be as fast as other sorting algorithms.</p><p><strong>Counting Sort </strong>is an algorithm that operates by tallying the frequency of each element in the array. It then utilizes this data to position each element accurately in the sorted array.</p><p>Counting sort exhibits a time complexity of <strong>O(n + k)</strong>, where k represents the number of unique elements in the array. Nevertheless, it necessitates extra memory space to hold the frequency counts.</p><p>In the realm of Python, the <strong>“sorted” function</strong> is a versatile and convenient tool for sorting arrays.</p><p>While not a traditional sorting algorithm, it utilizes an adaptive and stable sorting algorithm called <strong>Timsort</strong>, which is a hybrid sorting algorithm derived from merge sort and insertion sort.</p><p>Timsort shines in Python due to its efficiency, adaptability to different data distributions, and stable sorting behavior.</p><p>Additionally, Python’s “sorted” function allows custom sorting based on user-defined keys. It provides a key parameter for specifying a function to be called on each list element prior to making comparisons.</p><p>This flexibility makes it a powerful and user-friendly tool for sorting arrays in Python. Each algorithm brings its unique strengths and characteristics to the table, enriching the landscape of array sorting in C and Python.</p><h3>Real-Life Applications of Array Sorting Algorithms</h3><p>Array sorting algorithms find applications in various real-life scenarios, often behind the scenes, optimizing processes and improving efficiency. Here are a few examples:</p><ol><li><strong>Databases:</strong> Sorting algorithms are crucial in database management systems for organizing and retrieving data efficiently. When you search for a specific item in an online store or look up a contact on your phone, the underlying database likely uses sorting algorithms to locate the relevant information quickly.</li><li><strong>Search Engines: </strong><a href="https://www.linkedin.com/feed/update/urn:li:activity:7096411313358217216?utm_source=share&amp;utm_medium=member_desktop">Search engines</a> process vast amounts of data to provide relevant search results. Sorting algorithms play a role in organizing and ranking web pages, images, and other content to deliver accurate and timely search results.</li><li><strong>Financial Data Analysis: I</strong>n finance, sorting algorithms are used to analyze and process large sets of financial data. For example, stock market data, transaction records, and portfolio management benefit from efficient sorting to identify trends, anomalies, and investment opportunities.</li><li><strong>Multimedia Applications: </strong>Multimedia applications, such as photo and video editing software, often rely on sorting algorithms to manage and arrange large collections of media files. Sorting algorithms help users quickly locate and organize their multimedia content.</li><li><strong>Logistics and Scheduling: </strong>In transportation and logistics, sorting algorithms are used to optimize routes, schedules, and delivery sequences. They help streamline operations by arranging tasks, orders, or shipments in the most efficient order.</li><li><strong>Social Media and Content Platforms: </strong>Social media platforms and content-sharing websites use sorting algorithms to personalize content feeds, recommend relevant posts, and display trending topics. These algorithms help tailor the user experience based on individual preferences and engagement patterns.</li></ol><p>In essence, array sorting algorithms are fundamental tools that underpin many aspects of modern technology and everyday life, enabling efficient data organization, quick information retrieval, and streamlined processes across various domains.</p><h3>Tips To Master Sorting Algorithms in C and Python</h3><ul><li>Visualize! Draw diagrams or use online animations to understand different algorithms.</li><li>Start small, conquering smaller datasets before tackling larger ones.</li><li>Practice makes perfect! Write code for different sorting algorithms and compare their performance.</li><li>Don’t hesitate to seek help. Online forums and communities are brimming with friendly C programmers eager to share their knowledge.</li></ul><h3>Master Array Sorting Algorithms Today!</h3><p>Mastering these algorithms isn’t just about collecting shiny coding badges. It’s about laying the foundation for tackling real-world problems.</p><p>From <strong>optimizing search engines</strong> to <strong>analyzing financial data</strong>, sorting algorithms are the hidden gears that power countless applications.</p><p>They are the silent guardians of data integrity, the invisible hands that curate information, and the unsung heroes of efficient code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9866e9c8c44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uncovering the Basics of Shell Programming]]></title>
            <link>https://medium.com/@fredycheto/uncovering-the-basics-of-shell-programming-edcafea10192?source=rss-36013b85ff6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/edcafea10192</guid>
            <dc:creator><![CDATA[Fred Cheto]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 09:41:48 GMT</pubDate>
            <atom:updated>2023-12-11T10:07:38.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jUFPYyMKq_abw71S" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>UNIX’s<strong>(UNiplexed Information Computing System)</strong> popularity has grown due to its robust, user-friendly environment and the emergence of Linux. It has a variety of standard programs for tasks like file listing and email reading.</p><p>These programs can be combined to perform complex tasks. The <strong>Shell</strong>, an essential UNIX program, provides a consistent interface for executing other programs.</p><p>The Shell reads user commands and requests the UNIX kernel to execute them. The shell also offers advanced <a href="https://www.linkedin.com/pulse/unleashing-c-programming-dive-deep-linked-lists-fred-cheto/?trackingId=2BVv%2BDjyS1ueMa9oPaOEFg%3D%3D">programming</a> features like <strong>decision-making, command repetition, function creation, and variable storage.</strong></p><h3><strong>Types of </strong>Shell Programs and Their Prompts</h3><p>Shell programs act as your interface to the operating system. They interpret your commands and execute them using the kernel. Here’s a quick peek at different shells and their prompts:</p><h4><strong>Bourne Shell (sh)</strong></h4><ul><li>Prompt: $ (non-root), # (root)</li><li>Path: /bin/sh, /sbin/sh</li><li>Features: Simplest and most widespread, good for basic tasks.</li></ul><h4><strong>Bourne Again Shell (bash)</strong></h4><ul><li>Prompt: bash-VersionNumber$</li><li>Path: /bin/bash</li><li>Features: Powerful and versatile, expands on <strong>sh </strong>with features like history and command completion.</li></ul><h4><strong>C Shell (csh)</strong></h4><ul><li>Prompt: %</li><li>Path: /bin/csh</li><li>Features: C-like syntax, easier for programmers, less commonly used.</li></ul><h4>Korn Shell (ksh)</h4><ul><li>Prompt: $</li><li>Path: /bin/ksh</li><li>Features: Compatible with sh and csh, combines best features of both.</li></ul><h4><strong>Z Shell (zsh)</strong></h4><ul><li>Prompt: %</li><li>Path: /bin/zsh</li><li>Features: Modern and customizable, offers plugins and themes for enhanced experience.</li></ul><p>Each shell has its strengths and weaknesses. Choose the one that best suits your needs.</p><h3>Shell Commands</h3><p><a href="https://www.linkedin.com/pulse/7-things-we-learnt-from-apples-wwdc-23-fred-cheto?trackingId=2BVv%2BDjyS1ueMa9oPaOEFg%3D%3D&amp;lipi=urn%3Ali%3Apage%3Ad_flagship3_profile_view_base_recent_activity_content_view%3BhoT%2BoabrQ8a9j7EDvolzUA%3D%3D">Mac OS</a> or Windows operating systems allow you to click on the desired program to run it. However, we input the command’s name in UNIX and hit Enter to run it. To run a command that lists all current files and directories, we type:</p><pre>$ ls</pre><p>The $ symbol represents the prompt in UNIX. You can enter a command at any prompt and press Enter to execute it. The prompt disappears while the command runs and reappears once the execution is complete.</p><p>Shell commands are the building blocks of interacting with a UNIX system. They are simple, text-based inputs instructing the system to perform specific tasks. From file management to process control, shell commands offer a powerful and flexible way to interact with the system.</p><p>Here are other basic shell commands:</p><ul><li>cd: Changes the current directory.</li><li>pwd: Prints the path of the current directory.</li><li>cat: Displays the contents of a file.</li><li>cp: Copies files or directories.</li><li>mv: Moves or renames files or directories.</li><li>rm: Removes files or directories.</li></ul><p>These commands form the foundation of UNIX shell interaction. Users can perform complex tasks efficiently by combining these commands and using additional options.</p><h4>Complex Commands</h4><p>Complex commands consist of one command followed by a list of other commands. The formal syntax for a complex command is:</p><pre>$ command argument1 argument2 argument3 … argumentN</pre><p>Here are examples of complex commands:</p><ol><li><strong>Piping (</strong><strong>|)</strong>: This command allows you to use the output of one command as the input of another. For example, if you want to search for a specific file in a directory, you can use the ls command combined with the grep command:</li></ol><pre>$ ls -l | grep &quot;myFile.txt&quot;</pre><p><strong>2. Redirection (</strong><strong>&gt; and </strong><strong>&gt;&gt;)</strong>: These commands allow you to redirect the output of a command to a file. The &gt; command overwrites the file, while the &gt;&gt; Command appends to the file. For example, to save the list of files in a directory to a file, you can use:</p><p>files.txt # Overwrite $ ls -l &gt;&gt; files.txt # Append “&gt;</p><pre>$ ls -l &gt; files.txt  # Overwrite<br>$ ls -l &gt;&gt; files.txt  # Append</pre><p><strong>3. Command substitution (</strong><strong>$(command) or </strong><strong>`command`)</strong>: This allows you to use the output of a command as an argument to another command. For example, to change the directory of a particular file:</p><p>/dev/null)) “&gt;</p><pre>$ cd $(dirname $(find / -name &quot;myFile.txt&quot; 2&gt;/dev/null))</pre><h4>Compound Commands</h4><p>Compound commands in shell scripting allow multiple commands to be executed together. A compound command is a series of simple and complex commands divided by a semicolon (;). The formal syntax for a complex command is:<br>$ command1 ; command2 ; command3 ; ... ; commandN ;</p><p>They can be used in loops, conditional statements, or functions. Here’s an example of a compound command using a for loop:</p><pre>$ for i in {1..5}; do echo &quot;Number: $i&quot;; done</pre><p>This command prints the numbers 1 through 5, each on a new line.</p><h4><strong>Command Separators</strong></h4><p>Command separators in shell scripting execute multiple commands in a single line. Here are the most common command separators:</p><ol><li><strong>Semicolon (;)</strong>: Commands separated by a semicolon are executed sequentially. The shell waits for each command to terminate in turn. Example:</li></ol><pre>$ echo &#39;Hello, World!&#39;; ls</pre><p><strong>2. Ampersand (&amp;)</strong>: If a command is followed by an ampersand, the shell executes the command in the background. It doesn’t wait for the command to finish before moving to the next one. Example:</p><pre>$ echo &#39;Hello, World!&#39; &amp; ls</pre><p><strong>3. Double ampersand (&amp;&amp;)</strong>: Commands separated by double ampersands are executed sequentially, like with a semicolon. However, if a command fails (returns a non-zero status), the following commands are not executed. Example:</p><pre>$ cd /nonexistent/directory &amp;&amp; ls</pre><p><strong>4. Pipe (|)</strong></p><p>The pipe command separator connects one command&#39;s output to another&#39;s input. Helpful in chaining multiple commands.</p><pre>$ ls | grep file.txt | wc -l</pre><p><strong>5. Double Ampersand (&amp;&amp;)</strong></p><p>It executes the next command only if the previous command succeeds (exit code 0). It is helpful when building conditional command chains.</p><pre>$ make clean &amp;&amp; make &amp;&amp; ./program</pre><p><strong>6. Double Pipe (||)</strong></p><p>Executes the next command only if the previous command fails (non-zero exit code). Helpful in handling errors and providing alternatives. Example:</p><pre>$ make clean || make</pre><p><strong>7. Newline (\n)</strong></p><p>Terminates a command. Used to separate commands on different lines. Example:</p><pre>ls<br>pwd<br>echo &quot;Hello World&quot;</pre><p>Additional separators:</p><ul><li>&amp; (Background execution)</li><li>(), [] (Command grouping)</li></ul><p>These are just some basic examples. For more complex command chains, consider using shell scripting languages like Bash. These separators provide control over command execution, allowing for more complex and efficient shell scripts.</p><p>Remember, while these commands are powerful, they should be used cautiously to avoid unintended consequences. Always make sure you understand what a command does before executing it. Happy coding! Remember, the key to mastering UNIX is practice and exploration. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edcafea10192" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>