/*
I am trying to program a Tideman alternative method algorithm.
I am taking i/p through command-line-argument.
When I try to print the populated candidate array.
It is printing single characters when format specifier is char type. The result of other specifier is attached.
![]()
![]()
*/
/*
Same logic when executed on CS50 IDE, it prints the strings as expected.
I mean if the CLA is Alice Bob Charlie, then at 0th index Alice and so on...
This step is crucial as later the names from the voters would be compared.
I don't how to proceed from here. I came to know only about this when I reached the comparison stage. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define MAX 9
int preferences[MAX][MAX];
bool locked[MAX][MAX];
typedef struct
{
int winner;
int loser;
}
pair;
char candidates [MAX] = {0};
pair pairs[MAX*(MAX-1)/2];
int pair_count = MAX;
int candidate_count = MAX;
//Prototypes
bool vote (int rank, char name, int ranks[]);
void record_preferences(int ranks[]);
void add_pairs();
void sort_pairs();
void lock_pairs();
void print_winner ();
int main(int argc, char *argv[])
{
//Check for invalid usage.
if (argc < 4)
{
printf("Usage: tideman [candidate ...]\n");
return 1;
}
candidate_count = argc - 1;
if (candidate_count > MAX)
{
printf("Maximum number of candidates is %i\n", MAX);
return 2;
}
//popuplate the candidate array.
for (int i = 0; i < candidate_count; i++)
{
candidates[i] = argv[i+1];
printf("Candidate array: %c\n", *argv[i+1]);
}
}