+ 1

display variable using function

how to print my name using function in C program.. #inlcude<stdio.h> int variable(int); int main() { int x=jordan; printf("%d",variable); }

12th May 2018, 7:40 AM
Jordan
Jordan  - avatar
10 Respuestas
+ 2
Jordan is a string, so it has to be in ""
12th May 2018, 7:41 AM
Paul Grasser
Paul Grasser - avatar
+ 1
#include <stdio.h> int main(){ char name[]="Jordan"; printf("name is %s.\n",name); return 0; }
12th May 2018, 7:46 AM
MsJ
MsJ - avatar
+ 1
#include <stdio.h> /* function return type is void and it doesn't have parameters*/ void self() { printf("Hi\n"); printf("Jordan\n"); printf("that's what you want ?"); /* There is no return statement inside this function, since its * return type is void */ } int main() { /*calling function*/ self(); return 0; }
12th May 2018, 8:00 AM
MsJ
MsJ - avatar
+ 1
Thanks
12th May 2018, 8:05 AM
Jordan
Jordan  - avatar
+ 1
Donna gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with a null byte (aq\0aq). No check for buffer overrun is performed. fgets() reads in at most one less than sizecharacters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (aq\0aq) is stored after the last character in the buffer. so I prefer to use fgets it's more safe and on second note it's a user generated lessons so may be he is unknown of that
12th May 2018, 8:16 AM
MsJ
MsJ - avatar
0
but where is function brother... im not talking about arrray
12th May 2018, 7:53 AM
Jordan
Jordan  - avatar
0
Donna btw for printing only name it's good but it consider as a bad practice to use gets() The gets() function in C is inherentlyunsafe. ... However, the programmer uses the function gets() which is inherently unsafe because it blindly copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition.
12th May 2018, 8:08 AM
MsJ
MsJ - avatar
0
int var = chars? Printing out functions! what has happened to humanity.😶
12th May 2018, 8:33 AM
Akib
Akib - avatar