Get current line number in source file

Get line number

Define arbitrary line numbers for the source lines. Using the #line directive, you can specify an arbitrary line number at any point. The compiler then uses that line number for subsequent counts.


#include <stdio.h>
main()/*from   www .j a v  a  2s .  co  m*/
{
    printf("A\n");

     #line 100
    printf("B\n");
    printf("C FILE %s LINE %d\n", __FILE__, __LINE__ );
     #line 200

    printf("D\n");
    printf("E\n");
}

The code above generates the following result.





















Home »
  C Language »
    Language Advanced »




File
Function definition
String
Pointer
Structure
Preprocessing