Skip to content

A C program that generates two strings and a replacement character, then filters the first string by replacing any characters that appear in the second string with the specified replacement character.

Notifications You must be signed in to change notification settings

danieldotwav/C-String-Generator-Using-Array-Notation

Repository files navigation

Overview

This C program is designed to demonstrate basic string manipulation, input validation, and character replacement in C. It interacts with the user through the console to generate two strings and a replacement character, then filters the first string by replacing any characters that appear in the second string with the specified replacement character.

Features

  • Random Uppercase Letter Generation: Generates a string (s1) of 40 random uppercase letters.
  • User Input Validation: Prompts the user to enter a second string (s2) of uppercase letters, with length constraints. Also, prompts for a single replacement character. Validates all user inputs for correctness.
  • Character Filtering: Searches the first string (s1) for occurrences of any characters present in the second string (s2) and replaces them with a user-specified character (ch).
  • Program Restart Option: Allows the user to run the program multiple times without restarting the executable.

How to Compile and Run

  1. Ensure you have a C compiler installed, such as GCC or Clang.
  2. Compile the program using your compiler. For example, with GCC, you would use the command gcc -o charfilter charfilter.c.
  3. Run the compiled program from the command line. On Windows, you might type charfilter.exe, or on Linux/macOS, ./charfilter.

Usage Instructions

  1. Start the program: Follow the on-screen instructions. The program will first generate a random string of uppercase letters.
  2. Enter s2 String: When prompted, enter a string of uppercase letters (A-Z) within the length limits specified by the program.
  3. Enter Replacement Character: Enter a single character that will replace occurrences of s2 characters in s1.
  4. Review Results: The program will display the original s1 string, the user-entered s2 string and replacement character, and the filtered s1 string.
  5. Repeat or Exit: Decide whether to run the program again or exit based on the prompt.

Functions

  • generateS1(): Generates the s1 string with random uppercase letters.
  • generateS2(): Takes user input for the s2 string, ensuring it only contains uppercase letters and adheres to length restrictions.
  • getReplacementCharacter(): Prompts the user for a single character, used for replacement in the filtering process.
  • strfilter(): Replaces occurrences of s2 characters in s1 with the replacement character.
  • isUpperCaseLetter(): Helper function to check if a character is an uppercase letter.
  • duplicateArray(): Duplicates the s1 array into another array for preservation before modification.

Developer Notes

  • The program disables security warnings in Microsoft Visual Studio with _CRT_SECURE_NO_WARNINGS.
  • Make sure to handle the input buffer carefully, especially when validating user inputs.
  • The program uses the standard C library functions for I/O and string manipulation.

About

A C program that generates two strings and a replacement character, then filters the first string by replacing any characters that appear in the second string with the specified replacement character.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages