GUYS I"M ACTUALLY BACK. I CANT FIGURE THIS OUT I"M STUCK!!
so I made a separate function (because I couldnt figure out how to include it in the main -__-) that's supposed to output the largest element of the array...somehow when i run the program, that function is completely ignored...why?! :O
here's my program:
Code:
/*Written by: Kalpana Chinnappan
Date: January 17, 2013
Homework 1
*/
#include <stdio.h>
void countStudents(int[]);
void getLargest(int[]);
int main (void)
{
int nums[50]; //up to 50 element int array
FILE *fp1; //file pointer
int i;
int size, big;
//****************** code starts here ***************
for(i=0;i<10;i++) //initialize array with 0
nums[i]=0;
i=0; //clean up and initialize LCV
if ((fp1=fopen("votes.txt","r"))==NULL)
{
printf("votes.txt failed to open\n");
return 1;
}
else
while((fscanf(fp1,"%d",&nums[i]))!=EOF) //scanf and check EOF
{
printf("num[%d] is %d\n",i+1,nums[i]);
i++;
}
countStudents(nums);
getLargest(nums);
return 0;
}
void countStudents(int nums[])
{
int total = 0;
int count;
for (count = 0; count <=50; count ++)
{
if (nums[count] > total)
{
total = nums[count];
}
}
printf("The total number of students is: %d\n", nums[count]);
}
void getLargest(int nums[])
{
int i, big, size;
for (i=0; i<size; i++)
scanf("%d", &nums[i]);
big=nums[0];
for (i=1; i<size; i++)
{
if (big < nums[i])
big=nums[i];
}
printf("\nBiggest: %d", big);
}