[cs631apue] non-homework: welcome.c

sshah83 sshah83 at stevens.edu
Sun Sep 14 08:59:01 EDT 2014

After compiling welcome.c program, it gives below result:

welcome.c:5:2: warning: format '%s' expects argument of type 'char *', 
but argument 2 has type 'int' [-Wformat]
welcome.c:6:1: error: expected ';' before '}' token

the error message is syntax error - it points to missing semicolon at 
line 6.
The second warning is about int being used as char* which implies wrong 
type returned by getlogin() function.

If I turn on all warnings using below command :
gcc -Wall welcome.c -o welcome.out

I see the exact warning leading to the implicit function declaration
welcome.c:5:2: warning: implicit declaration of function 'getlogin' 

This warning means function prototype for getlogin() is missing and the 
"implicit function declaration" rule in C language means that a default 
declaration that returns int is created implicitly 

The fix would be to include the correct header file which has the right 
function prototype

#include <unistd.h>

On 09/12/2014 9:47 PM, Jan Schaumann wrote:
> Hello,
> Remember the welcome.c program you tried to run in our first class?  If
> you didn't get it to run (and run as expected), revisiting that would 
> be
> a good exercise.  Can you explain why/how it fails, and what the
> compiler error or warning messages mean?  How did you resolve the
> problem?
> -Jan
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue

More information about the cs631apue mailing list