This is a little C dialect program that can read a content document. The system is given document name as summon parameter and it peruses the record line by line. The system will print out number of characters and words in every line. The system will likewise print out the quantity of lines in the content record. Document name ought to contain complete physical way or just the record name if document is available in the same index as project.

view sourceprint?

01.

/*******************************************************

02.

* MYCPLUS Sample Code - http://www.mycplus.com ; *

03.

*

04.

* This code is made accessible as a support of our *

05.

* guests and is given entirely to the *

06.

* motivation behind delineation. *

07.

*

08.

* Please guide all request to saqib at mycplus.com *

09.

*******************************************************/

10.

11.

#include <stdio.h>

12.

13.

int principle (int argc, scorch *argv[]){

14.

Document *fp;

15.

int nchars, nwords, nlines;

16.

int lastnblank;/* 0 iff the last character was a space */

17.

roast c;

18.

19.

20.

if(argc!=2){

21.

printf("Usage: %s filenamen", argv[0]);

22.

exit(0);

23.

}

24.

if((fp=fopen(argv[1],"r"))==NULL){

25.

perror("fopen");

26.

exit(0);

27.

}

28.

nchars=nwords=nlines=lastnblank=0;

29.

while((c=getc(fp))!=EOF){

30.

nchars++;

31.

on the off chance that (c=='n'){

32.

on the off chance that (lastnblank)

33.

nwords++;

34.

printf("words=%d, characters=%dn", nwords, nchars);

35.

nchars=nwords=lastnblank=0;

36.

nlines++;

37.

}else{

38.

on the off chance that (((c==' ')||(c=='t'))&(lastnblank))

39.

nwords++;

40.

lastnblank=((c!=' ')&&(c!='t'));

41.

}

42.

}

43.

printf("lines=%dn", nlines);

44.

fclose(fp);

45.

}</stdio.h>
 
Top