1) Write a program to count the lines in a file. An example file:1.txt is attach
ID: 3878269 • Letter: 1
Question
1) Write a program to count the lines in a file. An example file:1.txt is attached. The program will take one argument - the name of the file to be opened and read.
2) Average the numbers found in the attached file 1.txt
3) Find the max, min, variance, and standard deviation in the attached file 1.txt
4) Write a program to show the endianness of file 1.txt
5) Write a program to find the relative time of the following operators: interger +, integer -, integer *, integer /, integer %, float +, float -, float *, and float /.
6) Write a recursive program that causes the program to crash. How calls does it take before it crashes?
Explanation / Answer
1-In order to count number of lines in a program you can use the following code-
#include<stdio.h>
#include<stdlib.h>
void main(void)
{
char *file = "xyz.txt";
countLines(file);
}
void countLines(char *file){
FILE* fp = fopen(file, "r");
int c, counter= 0;
do
{
c = fgetc(fp);
if(c == ' ')
counter+;
}
while (c != EOF);
if(c != ' ' && counter != 0)
counter++;
fclose(fp);
printf("Number of lines in %s = %d",file, counter);
}
Note-For other questions to be answered please provide as seprate questions
Thankyou
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.