Re: small string question



"Bill Cunningham" <nospam@xxxxxxxxx> wrote in comp.lang.c:

As I have been studing my tutorial I came up with this question. I
took char passw(char name[]);


In C, you can't pass an array by value. The language's misleading syntax, however, would have you believe that you can. The following three functions are identical:

void Func(char *name) { *name = 0; name = 0; }
void Func(char name[]) { *name = 0; name = 0; }
void Func(char name[72]) { *name = 0; name = 0 }

In the third one, 72 is ignored. All you've got is a non-const pointer in all three cases


and initialied this function in a header with other includes for
standard library headers.


We declare a function in a header file, and define it in a source file. Another name for a declaration is a "prototype". I've never see people use the word "initialiser" though in referring to a function declaration. Here's what an initialiser is in C:

int arr[5] = {7,3,2,3,4};


This doesn't seem to work so is what I want
this?

char passw(char *name);


This is no different from your previous declaration.


I haven't got to pointers in the tutorial and I'm taking my time. But
in this particualr function should it be initialized with a pointer?
Does char *name; equal char name[] ?


Sorry I'm not sure what you're asking.

--
Tomás Ó hÉilidhe
.



Relevant Pages

  • Re: Newbie question
    ... struct data {char question; ... object is declared as the same type every time, as in a header file that can be shared with all code files. ... declaration that is compatible) as often as you want, but that is NOT what the header does, the header defines the object. ...
    (comp.lang.c)
  • Re: jni problem linking into existing s.o. lib with externs
    ... and declared separately (with extern, ... in a header file). ... BOB.h: extern char *ERRMSG ... you include BOB.h to see the declaration. ...
    (comp.lang.java.programmer)
  • Re: MFC dll and exe porting to 64-bit
    ... Why the obsolete 'char *' instead of the proper LPTSTR? ... We are no longer programming 16-bit windows in an 8-bit character world, ... string arguments should probably be LPCTSTR, that is, const parameters. ... declaration of the function itself, in context (meaning show the surrounding class ...
    (microsoft.public.vc.mfc)
  • Re: malloc warning gcc > 4.0
    ... > char* p; ... > warning: incompatible implicit declaration of built-in function 'malloc' ...
    (comp.lang.c.moderated)
  • Re: Banks and economy
    ... char cptr; ... I'm assuming that it's at file scope, because otherwise the array declaration wouldn't be allowed. ... In some cases, a tentative definition with no corresponding external definition ends up being treated as the actual definition, with an implicit initializer of 0. ...
    (comp.lang.c)