0

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!

4
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by jim mcnamara
0
#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. 
*/
0

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);
    
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.