top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+2 votes
417 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
...