Question

Write a line of code that will declare a file variable named data. Assuming that the...

Write a line of code that will declare a file variable named data.

Assuming that the variable data was correctly created in the previous problem, write a line of code that will associate the variable with a file named grades.txt that is being opened for reading.

Assuming that grades.txt only contains integers, write a line of code that will use the variable data to read in the first integer and store in a variable named test1 that has already been declared.

ANSWER IN C PLEASE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(){
   FILE *file;                                   //get the file pointer
   char filename[190],c;          
   printf("Enter the filename to open\n");       //Enter the name of the file with complete path
   scanf("%s",filename);                      
   file = fopen(filename,"r");                   //opening file
   if(file == NULL)
   {
       printf("Can not open file\n");           //if not found or wrong input
       exit(0);
   }
   c = fgetc(file);                           //reding file data
   while(c!=EOF)              
   {  
       printf("%c",c);                           //printing data character by character
       c = fgetc(file);                       //getting next character
   }
   fclose(file);                               //closing file
}

THANKS

Add a comment
Know the answer?
Add Answer to:
Write a line of code that will declare a file variable named data. Assuming that the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Create a binary data file) Write a program to create a file named CreateBinaryFile.dat if it...

    (Create a binary data file) Write a program to create a file named CreateBinaryFile.dat if it does not exist. Append new data to it if it already exists. Write 50 integers created randomly into the file using binary I/O.

  • (Create a text file) Write a program to create a file named Exercise17_01.txt if it does...

    (Create a text file) Write a program to create a file named Exercise17_01.txt if it does not exist. Append new data to it if it already exists. Write 150 integers created randomly into the file using text I/O. Integers are separated by a space.

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Using netbeans to write a program to create a file named CreateBinaryfile.txt if it does not...

    Using netbeans to write a program to create a file named CreateBinaryfile.txt if it does not exist. Append new data to it if it already exists. Write 20 integers created randomly into the file using binary I/O. Thanks.

  • implicit none !   Declare File Read Variables     CHARACTER(255) :: Line     INTEGER :: CP !...

    implicit none !   Declare File Read Variables     CHARACTER(255) :: Line     INTEGER :: CP ! Character position in Line     INTEGER :: File_Read_Status !   Declare character constants     CHARACTER :: Tab > ACHAR(1)     CHARACTER :: Space = " " !   Read all lines in the file         DO             READ(*,'(A)',iostat = File_Read_Status) Line !       Exit if end of file             IF (File_Read_Status < 0) EXIT !       Skip leading white space          DO CP = 1, LEN_TRIM(Line)              IF...

  • A file named "numbers.txt" contains an unknown number of lines, each consisting of a single positive...

    A file named "numbers.txt" contains an unknown number of lines, each consisting of a single positive integer. Write some code that reads through the file and stores the largest number read in a variable named "maxvalue". Use Python

  • Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from...

    Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...

  • Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this...

    Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...

  • Question 2 (a) Provide a single line of C++ code that will declare a variable that...

    Question 2 (a) Provide a single line of C++ code that will declare a variable that points to a string value, the variable is named x. [2 marks] (b) You have array c declared as string *c [5]; Give the single line of C+ + code that will assign the string pointer stored in variable x (from above) to the third element of the array c. [2 marks] (c) Write a for loop that initialises the contents of each element...

  • in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file...

    in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT