Complete the steps outlined below. 11 lab 7.cpp CS102 Fall 2016 file Read in a s
ID: 3810947 • Letter: C
Question
Complete the steps outlined below. 11 lab 7.cpp CS102 Fall 2016 file Read in a single line of data from the data sinclude int main(void) char studentName[15]; variable to hold student name final test grade int final; II STEP 1: Add a declaration for a file variable named myinput. Add a to open the input file using myinput. Remember to /I use the correct format opening a f for reading STEP 3: a statement (or statements to read first line of data from Add the file into the two variables I provided for you above. STEP 4: Print the student's name and final exam grade to the s (not to a file). printf ("In End Program. Vn"); return 0Explanation / Answer
PART 1
#include <stdio.h>
int main(void)
{
char studentname[15];
int final;
FILE *myinput;
myinput=fopen("filename","r");
fscanf(myinput,"%s",studentname);
fscanf(myinput,"%d",&final);
printf(" Student Name: %s",studentname);
printf(" Student Marks: %d",final);
fclose(myinput);
printf(" End Program. ");
return 0;
}
Part 2
#include <stdio.h>
int main(void)
{
char studentname[15];
int final;
FILE *myinput;
myinput=fopen("filename","r");
while(!feof(myinput))
{
fscanf(myinput,"%s",studentname);
fscanf(myinput,"%d",&final);
printf(" Student Name: %s",studentname);
printf(" Student Marks: %d",final);
}
fclose(myinput);
printf(" End Program. ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.