Actually for C, the proper way should be to use "malloc" first. I also rusty liao :bsmilie:
Yes... that is what I am about to point out...
malloc ... nostalgic juz remember to "free" :bsmilie:
Actually for C, the proper way should be to use "malloc" first. I also rusty liao :bsmilie:
no lah use sbrk better and nmap is even better.
if that code is recursive good luck. hehehe
void getname( char[])
{
getname( char);
}
:bigeyes:
if not wrong... the sentence will stick all together...
pls enter name: Simonyour name is Simon
correct me if wrong.
You have to press Enter after you entered the name, so there will be a newline.
Oh.. tot gets will not recognize "ENTER" as a valid character so it would just terminate gets ?
it would print as a new line ? :think:
Wahaha too lazy to test it out.. got to dig up my C++ installer...
:bigeyes:
u get an error when u compile this..
To my understanding.. the 'return' is to return back to the previous command it is executing... Not to return any value, int or char......
#include <stdio.h> : declares standard i/o library
void getname (char n[20]); : declares a function call "getname" with char n
of 20 characters ( not string )
main() : main body
{
char name[20]; : declares local variable char "name" of 20 characters
getname(name); : runs function "getname" with variable name
printf("your name is %s\n", name); : print out input variable "name" and print new line
return(0); : end prog.}
void getname (char n[20]) : function "getname" with variable of 20 character max
{
printf("pls enter name: "); : obvious
gets(n); : get input as string:variable'n' is throw back as "name"
return; // <====== need to return? : how else to end a function than return ??
}
if not wrong... the sentence will stick all together...
pls enter name: Simonyour name is Simon
correct me if wrong.
TS u revising for ur job interview ?
:bsmilie: :bsmilie:
Eh, that piece of code posted by threadstarter is correct. I've tried it out on my computer and it works. There is no need to explicitly return n back to main(). The array parameter for getname() is converted into a pointer parameter by the compiler, so it is pass-by-reference.
TS u revising for ur job interview ?
hello guys, need some help here its been a long time i've touch this and im revising my work now, so need some help as i have something that im not too sure of....so here it is
#include <stdio.h>
void getname (char n[20]);
main()
{
char name[20];
getname(name);
printf("your name is %s\n", name);
return(0);
}
void getname (char n[20])
{
printf("pls enter name: ");
gets(n);
return; // <====== need to return?
}
this is an example from a book, so i was wondering if this book is wrong...
would i need to return the variable "n" back to main, in order for main function to printf it?