top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to write a C program, that prints its executable/binary file name on execution?

+2 votes
128 views
How to write a C program, that prints its executable/binary file name on execution?
posted Nov 26, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

Try this ,

#include <stdio.h>

int main(int argc,char *argv[])
{
    printf("executable name %s\n",argv[0]);
    return 0;
}
answer Nov 27, 2014 by Bheemappa G
+1 vote
#include<stdio.h>
#include<string.h>
main(int argc,char **argv)
{
  char ch[20];
  ch = strtok(argv[1],".");
  strcat(ch,".o");
  printf("executalbe file name is %s\n",ch);
}
answer Nov 27, 2014 by Chirag Gangdev
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...