Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <limits.h>
- #include <errno.h>
- #define MAX_A 3
- #define MAX_LEN 202
- #define NAME_LEN 100
- struct vote_4_me{
- char fname[NAME_LEN];
- char lname[NAME_LEN];
- int vote;
- };
- void start_mess(void);
- void get_votes(void);
- int chop_string(struct vote_4_me *st, char *s, int c);
- void stars(int am);
- int main() {
- char run='y',yes='y';
- struct vote_4_me vfm[MAX_A];
- char buff[MAX_LEN];
- int vts,count=0;
- // strol
- int val,base;
- char *string, *endptr;
- while(run=='y'){
- start_mess();
- fgets(buff,MAX_LEN,stdin);
- printf("\n%s\n",buff);
- if(chop_string(vfm,buff,count))
- continue;
- while(yes=='y'){
- get_votes();
- fgets(buff,MAX_LEN,stdin);
- base=atoi(buff);
- printf("You entered -> %d\n",base);
- if(!base){
- printf("\nERROR -> %d\n\n",base);
- continue;
- }
- else
- {
- yes='n';
- }
- } // End while
- yes='y';
- vfm[count].vote=base;
- count++;
- if(count == MAX_A) run='n';
- } // end while
- stars(45);
- for(int i=0;i<count;i++){
- printf("%s %s\n Has %d votes\n",
- vfm[i].fname,vfm[i].lname,vfm[i].vote);
- }
- stars(45);
- return 0;
- }
- void start_mess(void)
- {
- printf("HELLO\n"
- "Enter persons first last name\n");
- }
- void get_votes(void)
- {
- printf("Enter amount of votes\n");
- }
- int chop_string(struct vote_4_me *st, char *s,int c)
- {
- char *tok;
- char *tmp;
- int i;
- tok=strtok_r(s," ",&tmp);
- for(i=0;i<1;i++){
- strcpy(st[c].fname,tok);
- tok=strtok_r(NULL," ",&tmp);
- if(tok == NULL){
- printf("\n\nINPUT ERROR\n\n");
- return 1;
- }else{
- strcpy(st[c].lname,tok);
- }
- }
- return 0;
- }
- void stars(int am)
- {
- printf("\n");
- for(int i=0;i<am;i++)
- printf("*");
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement