Could anyone tell me the function this program is using?

#include <iostream.h>
#include <stdlib.h>

void My_Name_Is()

int main()
{
      My_Name_Is() //Calls function that prints user's name

}

Thanks!

Recommended Answers

All 3 Replies

That code is not valid. What are you trying to ask?

#include <iostream.h>
#include <stdlib.h>

/*
If you put a semicolon at the end of this line, then it becomes a function prototype.  It tells the compiler/linker/whatever that you will be using a function by the name of My_Name_Is which takes no parameters and doesn't return anything.
*/
void My_Name_Is()

int main()
{
      //This needs a semecolon after the ), too
      My_Name_Is() //Calls function that prints user's name

}

/* 
  You could put the definition of My_Name_Is() here.  Just rewrite the prototype, leaving the semicolon off this time; type opening and closing braces; and within the opening and closing braces type whatever code you want to use to print your name.  Some people don't use function prototypes and just type the definition before main().  Either way works. 
*/

I think he means what will print the username

/* windows: */
#include <windows.h>
void MyNameIs(void)
{
    char username[24]={0x0};
    GetUserName(username,sizeof(username));
     printf("%s\n", username);

}

/* unix */
#include <unistd.h>
void MyNameIs(void)
{
    char *username=getlogin();
    printf("%s\n", username);
    
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.