Unix wc-l Equivalent DOS Command Using C Program

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

The result in the windows command prompt

 

Related Tutorial Examples

  1. Parse Command Line Argument Input Using SHELL Script
  2. File Last Modification Information in SHELL Script
  3. Arithmetic Operations in SHELL Script Example
  4. UNIX Command Example: date - Display Date Information
  5. UNIX Command Example: cal - Display Calender
  6. UNIX Command Example: man - Display Command Mannual
  7. UNIX Command Example: wc - Word Count of a File
  8. 28 Tutorials to Learn Oracle
  9. 20 Steps to Make CakePHP Blog Project
  10. 19 Examples to Learn MySQL

No comments:

Post a Comment

leave your comments here..