Skip to content

Instantly share code, notes, and snippets.

View cearto's full-sized avatar

Cesar Torres cearto

View GitHub Profile
bool isValidPassword(char* passwordCandidate){
// Requirements: Assume false until proven valid
bool hasUpper = false;
bool hasLower = false;
// Assess password candidate
size_t n = strlen(passwordCandidate);
for(int i = 0; i < n; i++){
char x = passwordCandidate[i];
if(isupper(x)){ hasUpper = true; }
@cearto
cearto / main.c
Created September 10, 2025 18:40
#include <stdio.h>
#include <stdlib.h>
// Define an enum for traffic light colors
#define NUM_LIGHT_STATES 3
typedef enum { RED = 0, YELLOW, GREEN } Light;
#include <stdio.h>
// Excercise 1: Pointer Notation
// Use only pointer arithmetic
// and refrain from using index notation e.g, arr[0].
// Print out the non-zero values of arr.
// Do not use any control flow (loops, while, etc...).
// Output: 1234
int main(int argc, char* argv[])
{
@cearto
cearto / queue.c
Last active November 6, 2024 20:15
#include "queue.h"
// Initialize the queue with a specified capacity
bool queue_init(queue_t *queue, int capacity) {
assert(queue != NULL); // Ensure the queue pointer is valid
assert(capacity > 0); // Ensure the capacity is a valid positive number
// Setting members
queue->items = (int *) malloc(capacity * sizeof(int)); // Allocate memory on the heap
@cearto
cearto / queue.h
Last active November 6, 2024 20:16
#ifndef QUEUE_H
#define QUEUE_H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// Static queue structure
typedef struct {
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
// use typedef person struct
typedef struct Person {
char name[50];
int age;
float weight;
@cearto
cearto / csvreader.c
Last active September 18, 2024 22:07
/**
* INTEGER CSV READ OPERATION
* COMPUTES SUM per LINE in CSV
*/
// Libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@cearto
cearto / stringify.c
Last active September 16, 2024 20:50
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>
// Precondition:
// Accept a string
// Accept spaces
// Capital and lowercase letters
@cearto
cearto / problem.c
Created April 4, 2024 16:05
stack.h
#include <stdio.h>
#include "stack.h"
int main(void) {
// Your code here
printf("Hello, Stacks!\n");
Stack* s = stackCreate(INIT_STACK_CAPACITY);
stackPush(s, 10);
stackPush(s, 20);
stackPush(s, 30);
problem: Bit Storage Problem 3
suites:
- name: Asserts & Error Handling
pts: 10
tests:
- command:
- ./mysolution
- ../data/schedules5.txt
name: File Exists
solution: Program did not return a value