Display own name

This is a discussion on Display own name within the C Programming forums, part of the General Programming Boards category; Hello everyone, I need to do a program that displays its own name. So that, when I execute the program, ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    4

    Question Display own name

    Hello everyone,
    I need to do a program that displays its own name.
    So that, when I execute the program, let's say example.exe, "example" will be
    printed on the screen.
    Any ideas?

    Thanks in advance

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    argv[ 0 ] may contain the name of the executable. Look up command line arguments.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    5,889
    quzah's use of the word "may" reflects the fact that the content of argv[0] -if any - is implementation defined. argv[0] may be a NULL pointer. If it is not a NULL pointer, it may yield an empty string (""), the name of an executable, a full path to the executable, or some other representation.

    If argv[0] does not contain the name of the executable then the method to obtain it (eg API functions to call) is system dependent.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4
    Quote Originally Posted by grumpy View Post
    quzah's use of the word "may" reflects the fact that the content of argv[0] -if any - is implementation defined. argv[0] may be a NULL pointer. If it is not a NULL pointer, it may yield an empty string (""), the name of an executable, a full path to the executable, or some other representation.

    If argv[0] does not contain the name of the executable then the method to obtain it (eg API functions to call) is system dependent.
    Thanks for the fast reply. As a matter of fact argv[0] contains the filename, but it is giving me the whole path like c:desktop \bla bla\mypro.exe

    I only need the filename. Is there a way to parse only the filename from that ?

    Many thanks

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,981
    Yes, e.g., search for the last '\' and take the part after that.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Yes, e.g., search for the last '\' and take the part after that.
    I am so sorry but I am a newbie, could you please show me how to do this on C?

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Take a look at this tutorial It should help you implement what Laser said.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4
    Thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. int display help
    By darkevildemon in forum C Programming
    Replies: 7
    Last Post: 01-04-2008, 04:22 AM
  2. Display a .jpg
    By matth in forum Windows Programming
    Replies: 1
    Last Post: 03-22-2006, 10:08 AM
  3. Help display ***** for the value of an int
    By GUIPenguin in forum C++ Programming
    Replies: 12
    Last Post: 02-04-2005, 07:02 AM
  4. how to display a .jpg
    By Noobie in forum C++ Programming
    Replies: 10
    Last Post: 02-23-2003, 06:09 PM
  5. display
    By hen in forum C Programming
    Replies: 6
    Last Post: 08-10-2002, 03:14 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21