求一个投票程序的代码
(要求用指针实现,不能用数组)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN sizeof(char)
#define VOTES 5
int main(void)
{
void vote(char*, char*, char*);
char* a = "zhang";
char* b = "feng";
char* c = "keng";
vote(a, b, c);
return 0;
}
static void vote(char* p, char* p1, char* p2)
{
short a, b, c, j;
char* name = (char*)malloc(LEN*10);
a = b = c = j = 0;
printf("Please vote.\n");
while (j++ != VOTES) {
printf("Input name:");
if (name != NULL) {
gets_s(name, 9);
if (strcmp(name, p) == 0)
++a;
else if (strcmp(name, p1) == 0)
++b;
else if (strcmp(name, p2) == 0)
++c;
else {
printf("Input error!\n");
exit(0);
}
}
}
printf("Result\n%5s:%-3hd\n%5s:%-3hd\n%5s:%-3hd\n", p, a, p1, b, p2, c);
}