Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- typedef struct node node_t;
- struct node{
- int *n;
- node_t* next;
- };
- node_t* head;
- int read_one_vote(int no_of_candidates, int one_vote[]);
- int main(int argc, char* argv[]){
- head= NULL;
- int no_of_candidates = 5;
- int i;
- int *one_vote_array;
- one_vote_array = (int*)malloc(no_of_candidates*sizeof(int));
- for(i=0; read_one_vote(no_of_candidates,one_vote_array); i++){
- node_t* vote_node = (node_t*)malloc(sizeof(node_t));
- vote_node->n = one_vote_array;
- vote_node->next = head;
- head=vote_node;
- /*Here I just made a linked list with each structure holding an array of no_of_candidates numbers*/
- }
- /*When I try to print this*/
- node_t *temp = head;
- while(temp!=NULL){
- for(i=0; i<no_of_candidates;i++){
- printf("%d",temp->n[i]);
- }
- printf("%d",temp->next != NULL);
- temp=temp->next;
- /*It only prints the last 5 numbers i inputted in the console*/
- }
- return 0;
- }
- /*This function just reads 5 numbers in at once and puts then in the array one_vote, it returns 0 if no numbers are read, one if 5 numbers are read*/
- int read_one_vote(int no_of_candidates, int one_vote[]){
- int x,i =0;
- if(scanf("%d",&x) == 0){
- return 0;
- }
- else{
- one_vote[i] = x;
- for(i=1; i<no_of_candidates; i++){
- scanf("%d",&x);
- one_vote[i] = x;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement