Question

In: Computer Science

****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED Write a C...

****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED

Write a C program using system call I/O to determine how many lines there are in a text file.

Solutions

Expert Solution

Answer:

Code:

#include <stdio.h> 
#define MAX_FILE_NAME 100 
  
int main() 
{ 
    FILE *f; 
    int count = 0;  
    char filename[Your_file_name]; 
    char ch;  
  
    // Get file name from user. The file should be 
    // either in current folder or complete path should be provided 
    printf("Enter file name: "); 
    scanf("%s", filename); 
  
    // Open the file 
    f = fopen(filename, "r"); 
  
    // Check if file exists 
    if (f == NULL) 
    { 
        printf("Could not open file %s", filename); 
        return 0; 
    } 
  
    // Extract characters from file and store in character c 
    for (ch = getc(f); ch != EOF; ch = getc(f)) 
        if (ch == '\n') // Increment count if this character is newline 
            count = count + 1; 
  
    // Close the file 
    fclose(f); 
    printf("The file %s has %d lines\n ", filename, count); 
  
    return 0; 
} 

Hope I answered the question.

If you have any doubts, or queries, feel free to ask

I'll respond to you as soon as I can.

Have a nice day


Related Solutions

****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT YOU CANT USE fopen, fclose , etc *******You are ONLY ALLOWED TO USE SYSTEM CALL I/O such as read, write, open and close (System I/O functions) Write a C program using system call I/O to determine how many lines there are in a text file.
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT YOU CANT USE fopen, fclose , etc *****You are ONLY ALLOWED TO USE SYSTEM CALL I/O such as read, write, open and close (System I/O functions) Write a C program using system call I/O to a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated...
Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: For this exercise you should be able to write a logical expression (i.e., with logical operators) which checks if some integer x consists of exactly 5 digits. Ex: 30498 and -14004 are 5-digit numbers, while 1098, -1 and 34 are not. Complete the intQ2(intQ2_input) function that takes an input integer...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: A positive integer number is said to be a perfect number if its positive factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6=1+2+3. Complete the int Q6(intQ6_input, int perfect[])function that determines all perfect numbers smaller than or equal...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: (Pythagorean Triples) A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: Complete the int Q7a(intQ7_input) function takes only a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: Complete the int Q7a(intQ7_input) function takes a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use arrays...
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT