Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: ????????? ? ??????????? ???????? ??????? ? ?

Reply
Thread Tools

Re: ????????? ? ??????????? ???????? ??????? ? ?

 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-15-2006
Since I don't speak whatever language http://www.velocityreviews.com/forums/(E-Mail Removed) does, this is just
a generic tidying-up answer:

(E-Mail Removed) said:

> author* create_author(char *name,char *family, article *art)
> {
> author *tmpAut;
> ALLOCATE(tmpAut,author);


You don't supply a definition for this (presumably) macro, so I can't
comment on it.

> if (!tmpAut) return NULL;
> if (!(tmpAut->name=(char*)malloc(sizeof(char)*strlen(name)+1) )) return
> NULL;


You will need to #include <stdlib.h> for the malloc prototype and <string.h>
for strlen. Please note that the cast is unnecessary, and that sizeof(char)
is always, always 1 by definition.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
stasgold@gmail.com
Guest
Posts: n/a
 
      01-15-2006
Hi, Richard

Sorry for unknown symbols, just posted in the wrong group



Well, the question is why if I call function create_author from within
find_author , the pointer tmpAut is not updated and has the same
"garbage value as after tmpAut declaration

Code:
author* find_author(LinkedList authorsList,char* name,char* family)
{
        author *tmpAut;
        tmpAut=create_author(name,family,NULL);
             ...
Code:
author* create_author(char *name,char *family, article *art)
{
        author *tmpAut;
        ALLOCATE(tmpAut,author);
        if (!tmpAut) return NULL;
        if (!(tmpAut->name=(char*)malloc(sizeof(char)*strlen(name)+1)))
return
NULL;
        strcpy(tmpAut->name,name);
        if
(!(tmpAut->family=(char*)malloc(sizeof(char)*strlen(family)+1)))
return NULL;
        strcpy(tmpAut->family,family);
        tmpAut->articles=LinkedList_create(cpy_same,fre_none);
        if
(LinkedList_insertAfterCurrent(tmpAut->articles,art)!=LIST_SUCCESS)
return NULL;
        tmpAut->tGrade=0;
        tmpAut->cGrade=0;
        tmpAut->cWeight=0;
        tmpAut->tWeight=0; 
        return tmpAut; 


}
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-16-2006
(E-Mail Removed) said:

> Well, the question is why if I call function create_author from within
> find_author , the pointer tmpAut is not updated and has the same
> "garbage value as after tmpAut declaration


It is not obvious from your code why this should be failing. Assuming you
have the correct headers in place (these are not merely C superstitions -
they really are needed, especially stdlib.h and string.h in this case), I
can't see why tmpAut would retain its value after the create_author call.
It should take either NULL or the result of the malloc in create_author.

I suggest you remove your "BB-tags" and post a complete, compilable program
that demonstrates the problem as simply as possible. We might then have a
fighting chance of helping you to discover what is going wrong.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments