C programming.
Use open(), lseek(), and read() to get the integer from the second line of the text file.
The text file is in lines of 32 bytes, the integer is 6 bytes, as shown:
000000 xxxxxxxxxxxxxxxxxxxxxxxx
111111 xxxxxxxxxxxxxxxxxxxxxxx
222222 xxxxxxxxxxxxxxxxxxxxxxx
Program
#include<stdio.h>
#include<fcntl.h>
int main()
{
// open the the in read-only mode
int f = open("file.txt", O_RDONLY);
if (f ==-1)
{
// print program detail "Success or failure"
perror("Program");
}
long offset = 32;
// forward current position 32 bytes
lseek (f, offset, SEEK_CUR);
char buf[6];
// read 6 bytes of input store in buf
read(f, buf, 6);
// convert from string to int
int i = atoi(buf);
// display the integer
printf("%d", i);
close(f);
return 0;
}
Output:
111111
C programming. Use open(), lseek(), and read() to get the integer from the second line of...
//Done in C please!
//Any help appreciated!
Write two programs to write and read from file the age and first
and last names of people. The programs should work as follows:
1. The first program reads strings containing first and last
names and saves them in a text file (this should be done with the
fprintf function). The program should take the name of the file as
a command line argument. The loop ends when the user enters 0, the...
USE SCALA ONLY: Here is an example of “Our Language” 1. integer a 2. integer b 3. string name 4. a = 14 5. b = 27 6. c = a + b 7. name = “example program” 8. display name 9. display c 10. read a 11. b = a * a 12. display a 13. end Your interpreter will: (a) Create an empty Map[String, String] (b) Read the program (c) Print each line as it is read (d)...
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...
C programming. please include comments
In this lab, you will learn to read data from and write data to a file - another use for pointers. SAMPLE PROGRAM There are two sample programs this week - WriteFile.c and ReadFile.c. The first, WriteFile.c, allows the user to enter customer names (first, middle, and last), and writes each name to an output text file, customerNames.txt. formatted as: firstName middlelnitial lastName" After you've run it once, what happens to the names you added...
This is for C Programming
Write a program to open a jpeg file and read a byte of data 10 times and display each byte in hexadecimal format.
Write a C++ Program to do following: 1. Read every character from file char.txt using "get" and write it to a file char.bak using "put" 2. Read every second character from file char.txt using "get" and write it to a file charalternate.txt using "put" and "ignore" 3. Take input from user for offset and number of characters. For example if user enters 5 for offset and 10 for number of characters, then your program should copy 10 bytes from file...
In C Programming Language, write a simple program to read one text file and print to screen all its text. Make use of the stderr and exit program statements should there not be only one text file identified on the command line. If successful then before fclose of the text file, use the fputs program statement to write a line "72 degrees Sunny light wind. Nice!\n". print the return code of fputs (should be zero). close and exit. Test program...
Create a C program that will read from a file the first line of the file, and print that line to standard output., using buffers The file may have multiple lines, but only print the first. Use secure coding
C PROGRAMMING ONLY
22 2 points Write a function for the following specs: • type: int • parameter: character array • Behavior: o Open the file using the parameter for the file name in read mode. o Return O if the file opened successfully, 1 if unable to open the file. В І о A- A Ex x, EE 12 23 2 points Write a function for the following specs: type: void • parameters: FILE", int[], int size Behavior: o...
C
Programming
6 1 point Which function(s) can be used to open a file? fread fopen fscanf fstream file.open fopens 7 1 point Which function(s), is/are used to write text to a file? fprintf printf write fseek fwrite 8 1 point Which preprocessor directive is used to make a macro? #define #ifdef #include #macro #directive 1 point You cannot write the field values of a structure variable to a file. True False 10 1 point You can use the standard...