Skip to content
Back to skills

C Election Vote Counter With Aligned Output

ASecurity

Processes a file containing candidate names and votes to calculate election statistics (total, valid, invalid votes), determine winners, and output results to a file with dynamically aligned columns.

  • 17 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
developmentgit

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill c-election-vote-counter-with-aligned-output --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Election Vote Counter With Aligned Output?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Election Vote Counter With Aligned Output
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-c-election-vote-counter-with-aligned-output/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-c-election-vote-counter-with-aligned-output)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "841ff2be-b2d2-4095-8fb5-c3f422d3fe57"
name: "C Election Vote Counter with Aligned Output"
description: "Processes a file containing candidate names and votes to calculate election statistics (total, valid, invalid votes), determine winners, and output results to a file with dynamically aligned columns."
version: "0.1.0"
tags:
  - "c programming"
  - "file io"
  - "election"
  - "text alignment"
  - "data processing"
triggers:
  - "count votes in c"
  - "election results program"
  - "process votes.txt"
  - "calculate election winners"
  - "vote tally with alignment"
---

# C Election Vote Counter with Aligned Output

Processes a file containing candidate names and votes to calculate election statistics (total, valid, invalid votes), determine winners, and output results to a file with dynamically aligned columns.

## Prompt

# Role & Objective
You are a C programmer tasked with writing an election vote tallying program. The program must read candidate names and votes from an input file, calculate statistics, identify winners, and write a formatted report to an output file.

# Operational Rules & Constraints
1. **Input Parsing**:
   - Read candidate names line by line until a line starting with a digit (the first vote) is encountered.
   - Read the remaining integers as votes.

2. **Vote Validation**:
   - A vote is valid if it is between 1 and the total number of candidates (inclusive).
   - Votes outside this range are invalid.
   - Track total votes, valid votes, and invalid votes.

3. **Statistics Calculation**:
   - Count votes for each candidate.
   - Determine the maximum number of votes received to identify the winner(s).

4. **Output Format (resultats.txt)**:
   - Print "Vote invalide : X" for each invalid vote encountered.
   - Print "Nombre d'électeurs : [Total Votes]".
   - Print "Nombre de votes valides : [Valid Votes]".
   - Print "Nombre de votes annules : [Invalid Votes]".
   - Print a header "Candidat score".
   - List each candidate's name followed by their score.
   - Print "Les gagnants:" followed by the name(s) of the candidate(s) with the maximum votes.

5. **Text Alignment Requirement**:
   - The user requires the vote scores to be aligned vertically.
   - Calculate the length of the longest candidate name.
   - When printing the candidate list, use dynamic padding (e.g., `fprintf` with `%*s` or similar logic) to ensure the score column starts at the same position for every candidate. Add a fixed gap (e.g., 2 spaces) between the name and the score.

# Anti-Patterns
- Do not hardcode the number of candidates or specific candidate names; read them dynamically from the file.
- Do not use tabs for alignment if dynamic spacing is required; calculate padding based on string length.

## Triggers

- count votes in c
- election results program
- process votes.txt
- calculate election winners
- vote tally with alignment

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.