Unix wc-l Equivalent DOS Command Using C Program
create a file named "wc.c" then copy and paste the below code:
#include <stdio.h>
int main(int argc, char *args[])
{
FILE * FilePointer;
char Buffer[1024];
//char FileWithLocation[] = "C:\\TC\\file\\HW_EXPORT_28_RAFM_FILE_11.04.11.CSV";
long LastLine=0;
//puts(args[1]);
FilePointer = fopen(args[1],"rb");
while(fgets(Buffer,1024,FilePointer)!=NULL)
{
LastLine++;
}
fclose(FilePointer);
printf("%ld",LastLine);
printf("");
return 0;
}
Unix wc -l Equivalent DOS Command Using C Program
Now compile the program & make binary file and run the program(wc.exe) from command prompt by passing a text/csv file name as command line argument & get some interesting results as follows:
Unix wc -l Equivalent DOS Command Using C Program - output in the windows command prompt
Related Tutorial Examples
- Parse Command Line Argument Input Using SHELL Script
- File Last Modification Information in SHELL Script
- Arithmetic Operations in SHELL Script Example
- UNIX Command Example: date - Display Date Information
- UNIX Command Example: cal - Display Calender
- UNIX Command Example: man - Display Command Mannual
- UNIX Command Example: wc - Word Count of a File
- 28 Tutorials to Learn Oracle
- 20 Steps to Make CakePHP Blog Project
- 19 Examples to Learn MySQL

No comments:
Post a Comment
leave your comments here..