Segmentation fault while trying to run C program.
ok. so i wrote a program to fill an array with 100 random numbers ranging from 1 - 200. i compiled the program using gcc. the program successfully compiled but when i try to run it i get a segmentation fault. here is the code. i put *** on the line that gdb indicated was the problem.
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
//Function Declarations
void loadTlist (int tList[]);
void printResults (int tList[]);
int main()
{
// Local Declarations
int tList [100] = {0};
// Statements
loadTlist (tList);
printResults (tList);
return 0;
} //main
/*====================loadTlist===================
A function to fill the array designated 'tList' with
random numbers ranging 1 - 200.
*/
void loadTlist (int tList[])
{
// Statements
srand(time(NULL)); //set seed to time to ensure random number is different every time.
for(int i = 0; 1 < 100; i++)
***tList[i] = rand() % 200 +1;***
return;
} // Load tList
/*====================printResults====================
A function to print out the random array 'tList'
*/
void printResults (int tList[])
{
// Statements
for(int i = 0, line = 0; i < 100; i++, line++)
{
printf("%5d", tList[i]);
if (line == 9)
{
printf("\n");
line = 0;
}
}
return;
} // Print Results
any insight would be appreciated.
|