EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
Adds line numbersBy: mofm - Date Submitted: 2009-07-25 17:31:13 /*
fileex1.c
Input a text file a line at a time and output the
contents to the screen together with the line number.
*/
#include <stdio.h>
#include <stdlib.h>
FILE *fpin /* Define file pointer */
char file_name[13]
void process_files(void)
{
char buff[80]
int line_count
line_count=1
while(fgets(buff,80,fpin)!=NULL) /* Read in lines until EOF */
{
printf("%4d %s",line_count++,buff)
}
} /* End process_files */
void open_files(void)
{
printf("Enter filename : ")
scanf("%s",file_name)
if((fpin=fopen(file_name,"r"))==NULL) /* open file - with check */
{ /* Display error on fail */
printf("Cannot open file %s",file_name)
exit(1)
}
} /* End open_files */
void main(void)
{
open_files()
process_files()
fclose(fpin)
return 1
} /* End of main program */
|
| Return to
ajax category list |
|
|
Who's Online
416 Guests, 93 Users 7A69, ThaKeeper, hemiptera, Ausome1, zofy, sabre725, chrbarrol, dark_void, towncrown, EngGi235, blink_212, klesco, vapour, _InSane_, LordHelmet, BnE, N4g4c3N, th3punish3r, locust, c0re, iwanlearn, Anderl, ghostraider100, Ghostrider, eliking510, harsha2hack, NotMyOwn, Calumoo, MajorDeath, Rex_Mundi, bhoang93, r!v3rTw!ggz, jarlskov, invas10n, snozzberries, Nusquam-Redono-Sapientia, data, zeth, psychomarine, yuka, DnA-Ender, 454447415244, Ultraminor, T-Metal, antibubbles, raven001, aVoid, Psiber_Syn, sirEgghead, Protagoras, niggletandco, Vahakn, Chaplin, BinaryShinigami, zoegeorgica, hacker807, Red_beard, eviscerator, TheFender, InjectioN, totalnoob, Posix, obrigadoo, cul8er, Mcasdf, teehee, Ops, Protest123, Blizer, gabel, Marian, Edika, Nasrudin, dochaley, TheRetech, j0sh, kcaz, cool.nik, Sand, SaMTHG, fawk3s, rajabaja, avalor, hettoo, mat_2010, barbseven, daandeveloper33, tommy1092, Likantrop7, sajan619, Knuppel, Distorted, Bloodmaster25 |
| |
|
|
|
|
|