CS September 27
CS September 27
c textoxt
Online C Compiler.
Code, Compile, Run and Debug C program online.
5 Write your code in this editor and press "Run" but ton to cmpile and execute it.
7 ***************************t*******t****t***tt****tt*tt *****t*t******ttt***t/
8
10
#include <stdio.h
#include <stdlib.h>
11 int main()
FILE file;
4
char
char ch[10]- "hello":
7
char str[10]-"world";
int characters, Words, 1ines;
mode
Open text. txt 1n
W
9
file
/*
topen"text.txt",
if file
"W");
20
Check opened successfully *
if (file == NULL)
9
fputs(str.file);
41
fclose(file);
Open text. txt in 'r' mode *
42 file fopen("text.txt", "r");
printing to consOle
4
while ((r= fgetc(file)) 1=EOF)
putchar
fclose (file);
return 0,
input
hello
hel1 oworl1d
Program finiahed with exit code 0
2 #include <stdio.h>
3 #include <stdlib.h>
4 int main()
11
/*Check if file opened successfully */
if (file == NULL
if(ch
Words+
ch =t ch= An ll ch
Increment words
(characters 0)
and lines for last word
words
lines*
printing to console*/
printi(in )
printi("Total characters %d\n", characters);
printf("Total words
9 %d in", words):
%d \n", lines);
40 printt (Total lines
* Open result. txt in 'w' mode */
42 fp fopen ("result, txt", "W)
*writing the result to file */
4 fprint (fp, "Total characters %din Total words d An Total lines = %d\n ", char
45 * Close files */
46
fclose(file);
47 TCLose(Tp);
48 return 0;
49
input
Total lines