Skip to main content

C program to read a file and display its contents along with line numbers before each line.


#include<stdio.h>
void main()
{
FILE *fp;
char ch;
char source[67];
int count = 1;
clrscr();
puts("enter the file name:");
gets(source);
fp=fopen(source,"r");// read only mode for the source file
if(fp==NULL)
{
puts("unable to open the file:");
getch();
exit();
}
clrscr();
printf("file name:%s",source);
printf("\n line:-%d\t",count);
while((ch=getc(fp))!=EOF)
{
if(ch=='\n')
{
count++;
printf("\nline:-%d\t",count);
}
else
{
printf("%c",ch);
}
}
printf("\n press any key...");
getch();
fclose(fp);
}

Also Read : 

1)  Principles of Server Virtualization

2) Top Ten Data Storage Tools

3) Implement a simple calculator (detailed comments on JAVA code)

4) What is a Livelock scenario in java?

5) What is Disk scheduling algorithm in java ( code Example) 

6) What is a Deadlock situation in Java? What are the minimum requirements for a Deadlock situation in a program in Java? How can we prevent a Deadlock in Java?

7) Recursion-maze problem - Rat in the Maze - Game

8) What are features ,  Advantages and disadvantages of Javascript?

9) C program to read a file and display its contents along with line numbers before each line.

10) C++ program to find LCM and HCF of given 3 numbers


11)  What is cloud computing technology and what are the concepts, principles, applications, and prospects for cloud computing technology?

12) What are the basic characteristics of enterprise cloud computing, and what are the main stages in the construction process?

13) 20 best practices for database design

14) Best practices for DB2 database index design

Comments