@nonpuz Yes you're totally correct!! AND I JUST FIGURED OUT MY LARGEST FUNCTION SO IT WORKS!!!!! Thanks soo much guys for thoroughly explaining this to me, and taking the time and being patient with me! I greatly appreciate it! Here is my fixed code that works!!
Code:
/*Written by: Kalpana Chinnappan
Date: January 17, 2013
Homework 1
*/
#include <stdio.h>
void countStudents(int nums[]);
void getLargest(int nums[]);
int main (void)
{
int nums[50]; //up to 50 element int array
FILE *fp1; //file pointer
int i;
//****************** 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 largest = 0;
int count;
for (count = 0; count < 10; count ++)
{
if (nums[count] > largest)
{
largest = nums[count];
}
}
printf("The largest value is: %d\n", largest);
}