System Software Gtu
System Software Gtu
Practical : 1
AIM : Write a C Program to count number of Characters, Words, lines
and Whitespace from the given input file.
Program :
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * file;
char ch;
int characters, words, lines, whitespace;
if (file == NULL)
{
printf("\nUnable to open file.\n");
printf("Please check if file exists and you have read privilege.\n");
exit(EXIT_FAILURE);
}
if (characters > 0)
{
lines++;
}
1|Page
Practical 1
System Software (3160715) 190160107096
printf("\n");
printf("Total characters = %d\n", characters);
printf("Total words = %d\n", words);
printf("Total lines = %d\n", lines);
printf("Total whitespace = %d\n", whitespace);
fclose(file);
return 0;
}
ss2.txt
Output :
2|Page
Practical 1