Posts

Showing posts with the label char

C: Print character codes in a table.

Image
A program that will output the printable characters for character code values from 0 to 127. Each character code is printed along with its symbol. Make sure the columns are aligned. UPGRADES to original exericse!      - User selects between 1-8 columns to display.      - CHAR_MAX to control upper limit of char codes. Git repo: https://github.com/pereiradaniel/beginning_c/blob/master/ch4/exercises/4_2/exercise4_2.c

C: Display A Char's Numerical Value.

Image
The char type in C is an integer which gets decoded as a character. You can print the char's numerical type. https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.c // Chars // Daniel Pereira, 16 November 2022. // Display a char and it's numerical value. #include <stdio.h> int main(int argv, char* argc[]) { char c = 0; printf("Enter a character: \n"); scanf(" %c", &c); printf("The character: %c\nIt's numerical value: %d\n", c, c); return 0; } https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.txt ==87== Memcheck, a memory error detector ==87== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==87== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==87== Command: ./char ==87== Enter a character: X The character: X It's numerical value: 88 ==87== ==87== HEAP SUMMARY: ==87== in use at exit: 0 bytes in 0 blocks ==87== total heap usage: 2 al...

C: Remove duplicate chars from a string.

  https://github.com/pereiradaniel/c_programs/blob/master/rem_dupl_char.c // Remove duplicate chars from a string. #include <stdio.h> #include <string.h> // Use string length function to find length of a string. // Create a function that removes duplicate chars after their first appearance in a string. void rem_dup(char* string) { // Find length of string: int length = strlen(string); // Returns length of str NOT including NULL term!!! // Use nested loops: // Outermost loop - Examines string one char at a time until length is reached. for (int i=0; i < length; ++i) { // Next loop checks to see if any other chars match the one at i: for (int j=i+1; j < length; ) // j is not incremented here! in case char at j needs removal { if (string[i] == string[j]) // Checks for dupl char { // Remove duplicate char from string: // Pull forward all remaining chars by 1 index....