Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The code compiles but I'm not sure why it crashes. The file im grabbing is a list with 100 names, one name per line. I'm
The code compiles but I'm not sure why it crashes. The file im grabbing is a list with 100 names, one name per line. I'm trying to use a for loop to iterate through every line until I get to the line I want and grab that name and store it into a char array. Please keep it to no other array than the one I've used.
The player will play against a simulated opponent. The opponent will be named by reading a name from a provided text file. You will pick the name by generating a random number between 0 and the number of names in the file and reading that number name in the file. The sample file provided will have 100 names. IE: If the code randomly generates 23 it would read and skip 22 names then read Delicia and store that as the opponent's name. Note: the longest name in the provided file is 9 characters long, so you can simply create a character array size 10 to fit any name: char name [10]; FILE *f; f = fopen("random_names.txt","r"); int namenum = Random InRange(1,100); int i; for(i = 0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started