473,473 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

could you help me about this problem?

#include "stdio.h"
#include "malloc.h"
struct student{
int age;
char *nms;
struct student *next;
};
struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";
struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!
while(ags!=0){
p=(struct student * )malloc(size);
nms=(char *)malloc(20);
p->age=ags;
p->nms=nms;
p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;
}
tail=p;
scanf("%d%s",&ags,nms);
}
return head;
}
int main(void) {
struct student *ptr=create();
while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);
free(ptr);
ptr=ptr->next;
}
}
************************************
i think that is no problem with it.but it doesn't work!
why?

Feb 27 '07 #1
21 2073
On Feb 27, 9:25 am, "softwindow" <softwin...@gmail.comwrote:
[...]
free(ptr);
ptr=ptr->next;
}}

************************************
i think that is no problem with it.but it doesn't work!
why?
You didn't give us much of a hint as to what you think "doesn't work"
means. But one obvious problem is the code above. Once you pass a
pointer to free, you can't then try to dereference it. Try something
like

tptr = ptr->next;
free(ptr);
ptr = tptr;

(with an appropriate declaration of tptr, of course.)

Regards,
-=Dave
Feb 27 '07 #2
On Feb 27, 10:25 am, "softwindow" <softwin...@gmail.comwrote:
#include "stdio.h"
#include "malloc.h"
struct student{
int age;
char *nms;
struct student *next;};

struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";
struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!
while(ags!=0){
p=(struct student * )malloc(size);
nms=(char *)malloc(20);
p->age=ags;
p->nms=nms;
p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;
}
tail=p;
scanf("%d%s",&ags,nms);
}
return head;}

int main(void) {
struct student *ptr=create();
while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);
free(ptr);
ptr=ptr->next;
}}

************************************
i think that is no problem with it.but it doesn't work!
If there is no problem, then why do you say it doesn't work.

Sorry, I am not a mind reader, you will have to spell out what exactly
your issue is.
why?

Feb 27 '07 #3
On Feb 27, 10:25 am, "softwindow" <softwin...@gmail.comwrote:
#include "stdio.h"
#include "malloc.h"
struct student{
int age;
char *nms;
struct student *next;};

struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";
struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!
What is your input, do you have enough memory allocated for 'nms'?
while(ags!=0){
p=(struct student * )malloc(size);
nms=(char *)malloc(20);
p->age=ags;
p->nms=nms;
p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;
}
tail=p;
scanf("%d%s",&ags,nms);
}
return head;}

int main(void) {
struct student *ptr=create();
while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);
free(ptr);
ptr=ptr->next;
}}

************************************
i think that is no problem with it.but it doesn't work!
why?

Feb 27 '07 #4
On 2月27日, 下午11时35分, "Dave Hansen" <i...@hotmail.comwrote:
On Feb 27, 9:25 am, "softwindow" <softwin...@gmail.comwrote:
[...]
free(ptr);
ptr=ptr->next;
}}
************************************
i think that is no problem with it.but it doesn't work!
why?

You didn't give us much of a hint as to what you think "doesn't work"
means. But one obvious problem is the code above. Once you pass a
pointer to free, you can't then try to dereference it. Try something
like

tptr = ptr->next;
free(ptr);
ptr = tptr;

(with an appropriate declaration of tptr, of course.)

Regards,
-=Dave
******************************************
i have change code as your code,it is my fault;
now i find it throw error at the first " scanf("%d
%s",&ags,nms); //-------------------here
"
when i input "10 finy", it throw a error.

Feb 27 '07 #5
On Feb 27, 10:49*am, "softwindow" <softwin...@gmail.comwrote:
On 2鏈27鏃, 涓嬪崍11鏃35鍒, "DaveHansen" <i...@hotmail.comwrote:


On Feb 27, 9:25 am, "softwindow" <softwin...@gmail.comwrote:
[...]
* * * * * * * * free(ptr);
* * * * * * * * ptr=ptr->next;
* * * * }}
************************************
i think that is no problem with it.but it doesn't work!
why?
You didn't give us much of a hint as to what you think "doesn't work"
means. *But one obvious problem is the code above. *Once you pass a
pointer to free, you can't then try to dereference it. *Try something
like
* *tptr = ptr->next;
* *free(ptr);
* *ptr = tptr;
(with an appropriate declaration of tptr, of course.)
Regards,
* *-=Dave

******************************************
i have change code as your code,it is my fault;
now i find it throw error at the first " scanf("%d
%s",&ags,nms); //-------------------here
"
when i input "10 finy", it throw a error.- Hide quoted text -

- Show quoted text -
okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)

Feb 27 '07 #6
On 2月28日, 上午12时13分, "Manish" <mar...@gmail.comwrote:
On Feb 27, 10:49 am, "softwindow" <softwin...@gmail.comwrote:


On 2月27日, 下午11时35分, "Dave Hansen" <i...@hotmail.comwrote:
On Feb 27, 9:25 am, "softwindow" <softwin...@gmail.comwrote:
[...]
free(ptr);
ptr=ptr->next;
}}
************************************
i think that is no problem with it.but it doesn't work!
why?
You didn't give us much of a hint as to what you think "doesn't work"
means. But one obvious problem is the code above. Once you pass a
pointer to free, you can't then try to dereference it. Try something
like
tptr = ptr->next;
free(ptr);
ptr = tptr;
(with an appropriate declaration of tptr, of course.)
Regards,
-=Dave
******************************************
i have change code as your code,it is my fault;
now i find it throw error at the first " scanf("%d
%s",&ags,nms); //-------------------here
"
when i input "10 finy", it throw a error.- Hide quoted text -
- Show quoted text -

okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)- 隐藏被引用文字 -

- 显示引用的文字 -
oh!my god! yes,you are right!
thanks!

Feb 27 '07 #7
Manish wrote:
"softwindow" <softwin...@gmail.comwrote:
>"Dave Hansen" <i...@hotmail.comwrote:
i have change code as your code,it is my fault;
now i find it throw error at the first " scanf("%d
%s",&ags,nms); //-------------------here
"
when i input "10 finy", it throw a error.

okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)
char *nms=" ";
nms doesn't have any storage that he's allowed to write to. It points
to a string literal.

See: http://c-faq.com/decl/strlitinit.html

John
Feb 27 '07 #8
"Manish" <ma****@gmail.comwrites:
[...]
okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)
The declaration of nms was

char *nms=" ";

so nms points to *two* bytes (' ' and '\0'). But, as someone else
already pointed out, you're not allowed to write to those bytes,
because they're part of a string literal. (You *might* get away with
it, but it's undefined behavior.)

Another comment: white space can make your code easier to read.
Rather than

char *nms=" ";

try:

char *nms = " ";

And so on.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 27 '07 #9
softwindow wrote:
>
#include "stdio.h"
#include "malloc.h"
struct student{
int age;
char *nms;
struct student *next;
};
struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";
struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!
while(ags!=0){
p=(struct student * )malloc(size);
nms=(char *)malloc(20);
p->age=ags;
p->nms=nms;
p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;
}
tail=p;
scanf("%d%s",&ags,nms);
}
return head;
}
int main(void) {
struct student *ptr=create();
while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);
free(ptr);
ptr=ptr->next;
}
}
/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>

#define LENGTH 19

struct student {
int age;
char *nms;
struct student *next;
};

struct student *create(void)
{
struct student *head = NULL;
struct student *tail = NULL;
struct student *p = NULL;
int ags;
char *nms;

do {
p = malloc(sizeof *p);
if (p == NULL) {
puts("p == NULL");
exit(EXIT_FAILURE);
}
p -next = NULL;
nms = malloc(LENGTH + 1);
if (nms == NULL) {
puts("nms == NULL");
exit(EXIT_FAILURE);
}
if (scanf("%d%s", &ags, nms) != 2) {
puts("scanf(\"%d%s\", &ags, nms) != 2");
exit(EXIT_FAILURE);
}
p - age = ags;
p - nms = nms;
if (head == NULL) {
head = p;
} else {
tail -next = p;
}
tail = p;
} while (ags != 0);
return head;
}

int main(void)
{
struct student *next;
struct student *ptr = create();

while (ptr != NULL) {
next = ptr -next;
printf("%d====%s\n", ptr -age, ptr -nms);
free(ptr -nms);
free(ptr);
ptr = next;
}
return 0;
}

/* END new.c */

--
pete
Feb 27 '07 #10
On 2月28日, 上午5时14分, Keith Thompson <k...@mib.orgwrote:
"Manish" <mar...@gmail.comwrites:

[...]
okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)

The declaration of nms was

char *nms=" ";

so nms points to *two* bytes (' ' and '\0'). But, as someone else
already pointed out, you're not allowed to write to those bytes,
because they're part of a string literal. (You *might* get away with
it, but it's undefined behavior.)

Another comment: white space can make your code easier to read.
Rather than

char *nms=" ";

try:

char *nms = " ";

And so on.

--
Keith Thompson (The_Other_Keith) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
**************************************
you say "you're not allowed to write to those bytes, because they're
part of a string literal"

but i try it,i can write bytes like follow:

char *nms=" ";
scanf("%s",nms);

you can try it.

Feb 28 '07 #11
softwindow wrote:
On 2?28?, ??5?14?, Keith Thompson <k...@mib.orgwrote:
>"Manish" <mar...@gmail.comwrites:

[...]
>>okay now let's see the '10' gets stored in ags and 'finy' which needs
5 (4 bytes for "finy" and 1 extra byte for '\0') bytes of storage
space, you try to store it in 'nms' which has how much space ... ?
(Ans. 1 byte)
The declaration of nms was

char *nms=" ";

so nms points to *two* bytes (' ' and '\0'). But, as someone else
already pointed out, you're not allowed to write to those bytes,
because they're part of a string literal. (You *might* get away with
it, but it's undefined behavior.)

Another comment: white space can make your code easier to read.
Rather than

char *nms=" ";

try:

char *nms = " ";

And so on.

--
Keith Thompson (The_Other_Keith) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

**************************************
you say "you're not allowed to write to those bytes, because they're
part of a string literal"

but i try it,i can write bytes like follow:

char *nms=" ";
scanf("%s",nms);

you can try it.
The standard says that the behavior is undefined if you attempt
to modify such a string. It is possible that *you* can do that
but that's not something you should rely on.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Feb 28 '07 #12
"softwindow" <so********@gmail.comwrites:
On 2月28日, 上午5时14分, Keith Thompson <k...@mib.orgwrote:
[...]
>The declaration of nms was

char *nms=" ";

so nms points to *two* bytes (' ' and '\0'). But, as someone else
already pointed out, you're not allowed to write to those bytes,
because they're part of a string literal. (You *might* get away with
it, but it's undefined behavior.)
[...]

Please trim quoted material. In particular, don't quote signatures
unless you're actually commenting on them.
**************************************
you say "you're not allowed to write to those bytes, because they're
part of a string literal"

but i try it,i can write bytes like follow:

char *nms=" ";
scanf("%s",nms);

you can try it.
As I write above:

You *might* get away with it, but it's undefined behavior.

The most likely results of attempting to modify a string literal are
(a) your program immediately crashes, or (b) it "works", and the
string literal is modified.

Undefined behavior doesn't mean that the system is going to stop you
from doing it. It means the behavior is undefined; anything can
happen, so it's entirely up to you to avoid doing it.

See question 1.32 in the comp.lang.c FAQ, <http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 28 '07 #13
softwindow <so********@gmail.comwrote:
>char *nms=" ";
scanf("%s",nms);

you can try it.
Let me try it... This is what happens when I run the program and type
'b':

$ foo
b
Segmentation fault

So it's not exactly working for me. :)

In addition to what others are saying about the behavior in this
instance being undefined, the standard says that string literals may be
in read-only memory, and can actually be shared in memory, for instance:

#include <stdio.h>

int main(void)
{
char *a = "foobar";
char *b = "foobar";
char *c = "frobozz";

printf("a = %p\n", a);
printf("b = %p\n", b);
printf("c = %p\n", c);

return 0;
}

prints the following on my system:

a = 0x8048524
b = 0x8048524
c = 0x804852b

(Note a and b point to the same place.)

So, on my system, if it were allowed, modifying a's "foobar" would
effectively also modify b's; it's probably not what was desired.

-Beej

Feb 28 '07 #14
Groovy hepcat softwindow was jivin' on 27 Feb 2007 07:25:48 -0800 in
comp.lang.c.
could you help me about this problem?'s a cool scene! Dig it!
>#include "stdio.h"
That should be:

#include <stdio.h>
>#include "malloc.h"
No such header. It should be:

#include <stdlib.h>
>struct student{
int age;
char *nms;
struct student *next;
};
struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";
Here you create a string literal of one character length, resulting
in two bytes being allocated (one for your single character, and one
for the terminating '\0'). This may be placed in memory marked as
being readable but not writable. String literals are not modifiable.
> struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!
And here you attempt to read an arbitrarily long string (likely more
than one character) into the non-modifiable, one character long string
literal, thus attempting to not only modify a non-modifiable object,
but actually overflow that, writing to memory you don't own; possibly
memory that doesn't even exist! BANG! And your program crashes. Or it
goes on "working", but ends up doing weird things to your hard drive.
Or it makes demons fly out of your nose.
Had you read the FAQ list of this newsgroup or simply lurked here
for a while you would know that scanf() is not the best thing to use
for interactive input. It is customary, upon first entering a
newsgroup, to read a month or two of articles (lurk) before posting
and to seek out and read the newsgroup's FAQ, if it has one. Failing
to do so before posting is very rude! Please read the FAQ
(http://www.eskimo.com/~scs/C-faq/top.html) before posting any more.
What is the user supposed to be enterring anyhow? A prompt would be
helpful.
> while(ags!=0){
p=(struct student * )malloc(size);
Don't cast the return from malloc(). Do check the return from
malloc().
> nms=(char *)malloc(20);
Don't cast the return from malloc(). Do check the return from
malloc().
> p->age=ags;
p->nms=nms;
Here you copy the address of your string literal to your struct
member. Thus, your struct member will point to your string literal. No
other storage has been set aside, and no data copied.
> p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;
A bit dodgy! I think it will probably work, since the else clause is
not executed first time around (because head == NULL first time
through the loop). But it doesn't look good to dereference tail above
the point where you actually set it to a useful value..., assuming p
actually does contain a useful value.
> }
tail=p;
scanf("%d%s",&ags,nms);
And again you attempt to write X characters (where X is some unknown
number) to a one character long string literal.
> }
return head;
}
int main(void) {
struct student *ptr=create();
Check the return value. It's always a good idea.
> while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);
And here you're trying to free memory that was not allocated by
malloc(), calloc() or realloc(). BANG! More undefined behaviour! More
nasal demons! Remember, the nms member of your structure points at a
string literal.
> free(ptr);
ptr=ptr->next;
And once again, BANG! You're dereferencing ptr after freeing the
memory it points at.
> }
return 0;
>}
************************************
i think that is no problem with it.
Think again! There are many problems here. There may be some I
haven't spotted; after all, I only gave your code a cursory look. Even
so, I still found many serous errors.
but it doesn't work!
why?
Because it's so severely broken.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Feb 28 '07 #15
On 2月28日, 下午1时19分, phayw...@alphalink.com.au.NO.SPAM (Peter "Shaggy"
Haywood) wrote:
Groovy hepcat softwindow was jivin' on 27 Feb 2007 07:25:48 -0800 in
comp.lang.c.
could you help me about this problem?'s a cool scene! Dig it!
#include "stdio.h"

That should be:

#include <stdio.h>
#include "malloc.h"

No such header. It should be:

#include <stdlib.h>
struct student{
int age;
char *nms;
struct student *next;
};
struct student *create(){
int ags=0,size=sizeof(struct student);
char *nms=" ";

Here you create a string literal of one character length, resulting
in two bytes being allocated (one for your single character, and one
for the terminating '\0'). This may be placed in memory marked as
being readable but not writable. String literals are not modifiable.
struct student *head=NULL,*tail=NULL,*p=NULL;
scanf("%d%s",&ags,nms); //-------------------here!!!!!!

And here you attempt to read an arbitrarily long string (likely more
than one character) into the non-modifiable, one character long string
literal, thus attempting to not only modify a non-modifiable object,
but actually overflow that, writing to memory you don't own; possibly
memory that doesn't even exist! BANG! And your program crashes. Or it
goes on "working", but ends up doing weird things to your hard drive.
Or it makes demons fly out of your nose.
Had you read the FAQ list of this newsgroup or simply lurked here
for a while you would know that scanf() is not the best thing to use
for interactive input. It is customary, upon first entering a
newsgroup, to read a month or two of articles (lurk) before posting
and to seek out and read the newsgroup's FAQ, if it has one. Failing
to do so before posting is very rude! Please read the FAQ
(http://www.eskimo.com/~scs/C-faq/top.html) before posting any more.
What is the user supposed to be enterring anyhow? A prompt would be
helpful.
while(ags!=0){
p=(struct student * )malloc(size);

Don't cast the return from malloc(). Do check the return from
malloc().
nms=(char *)malloc(20);

Don't cast the return from malloc(). Do check the return from
malloc().
p->age=ags;
p->nms=nms;

Here you copy the address of your string literal to your struct
member. Thus, your struct member will point to your string literal. No
other storage has been set aside, and no data copied.
p->next=NULL;
if(head==NULL){
head=p;
}else{
tail->next=p;

A bit dodgy! I think it will probably work, since the else clause is
not executed first time around (because head == NULL first time
through the loop). But it doesn't look good to dereference tail above
the point where you actually set it to a useful value..., assuming p
actually does contain a useful value.
}
tail=p;
scanf("%d%s",&ags,nms);

And again you attempt to write X characters (where X is some unknown
number) to a one character long string literal.
}
return head;
}
int main(void) {
struct student *ptr=create();

Check the return value. It's always a good idea.
while(ptr){
printf("%d====%s\n",ptr->age,ptr->nms);
free(ptr->nms);

And here you're trying to free memory that was not allocated by
malloc(), calloc() or realloc(). BANG! More undefined behaviour! More
nasal demons! Remember, the nms member of your structure points at a
string literal.
free(ptr);
ptr=ptr->next;

And once again, BANG! You're dereferencing ptr after freeing the
memory it points at.
}

return 0;
}
************************************
i think that is no problem with it.

Think again! There are many problems here. There may be some I
haven't spotted; after all, I only gave your code a cursory look. Even
so, I still found many serous errors.
but it doesn't work!
why?

Because it's so severely broken.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
thank a lot!

thanks for your excellent explaining!
Feb 28 '07 #16
"softwindow" <so********@gmail.comwrites:
On 2月28日, 下午1时19分, phayw...@alphalink.com.au.NO.SPAM (Peter "Shaggy"
Haywood) wrote:
[134 lines deleted]
>
thank a lot!

thanks for your excellent explaining!
There was no need to repeat the whole thing.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 28 '07 #17
Keith Thompson wrote:
>
"softwindow" <so********@gmail.comwrites:
On 2月28日, 下午1时19分, phayw...@alphalink.com.au.NO.SPAM (Peter "Shaggy"
Haywood) wrote:
[134 lines deleted]

thank a lot!

thanks for your excellent explaining!

There was no need to repeat the whole thing.
Sometimes I do that as a cheap and easy way of saving
the explanation in my email "Sent box".

--
pete
Feb 28 '07 #18
pete <pf*****@mindspring.comwrote:
Keith Thompson wrote:

"softwindow" <so********@gmail.comwrites:
[134 lines deleted]
>
thank a lot!
>
thanks for your excellent explaining!
There was no need to repeat the whole thing.

Sometimes I do that as a cheap and easy way of saving
the explanation in my email "Sent box".
That's all very well for you, but it is anti-social to then continue to
post it to a newsgroup. All good mail- and news-readers have features to
save a post without sending it. The saving is not the problem; the
unsnipped sending is.

Richard
Feb 28 '07 #19
pete wrote:
Keith Thompson wrote:
>"softwindow" <so********@gmail.comwrites:
.... snip ...
>>
>>thanks for your excellent explaining!

There was no need to repeat the whole thing.

Sometimes I do that as a cheap and easy way of saving
the explanation in my email "Sent box".
Hey, I have a patent on that. Cease and desist immediately, or you
will hear from my lawyers. (They also work for Microsoft. :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Feb 28 '07 #20
pete <pf*****@mindspring.comwrites:
Keith Thompson wrote:
>"softwindow" <so********@gmail.comwrites:
On 2月28日, 下午1时19分, phayw...@alphalink.com.au.NO.SPAM (Peter "Shaggy"
Haywood) wrote:
[134 lines deleted]
>
thank a lot!

thanks for your excellent explaining!

There was no need to repeat the whole thing.

Sometimes I do that as a cheap and easy way of saving
the explanation in my email "Sent box".
Fortunately, I don't recall ever seeing you do that here. Re-posting
an entire article to a newsgroup for your own minor convenience would
be anti-social. (E-mailing it directly to yourself would, of course,
be just fine.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 28 '07 #21
(Peter "Shaggy" Haywood) wrote:
softwindow wrote:
nms=(char *)malloc(20);
p->nms=nms;

Here you copy the address of your string literal to your struct
member. Thus, your struct member will point to your string literal. No
other storage has been set aside, and no data copied.
Actually he is setting the struct member to point to the malloc'd
space.
free(ptr->nms);

And here you're trying to free memory that was not allocated by
malloc(), calloc() or realloc(). BANG! More undefined behaviour! More
nasal demons! Remember, the nms member of your structure points at a
string literal.
So this is OK (ish).

Feb 28 '07 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rene | last post by:
Hi, I'm spend many hour to fix this problem, read many articles about it but no article gave a solution. To isolate the problem I've created in IIS6 (WServer2003) a virtual directory test to...
6
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database...
5
by: Data | last post by:
In my project I want to execute some commands on the remote machine. I am using .Net Remoting to achieve this. My server which is an exe is copied on the remote machine and it receives command from...
0
by: john | last post by:
I am occasionally getting a strange error when deploying an asp.net assembly to a \bin directory in our production environment. CSC0006: Metadata file xxxxx could not be found. We then have to...
4
by: Sven-Torben Janus | last post by:
I'm running an ASP.NET webapplication on a Windows 2000 Server SP4 machine with .Net Framework 1.0 installed. The ASP.Net application uses impersonation (windows domain account). This is needed...
5
by: Verane | last post by:
Hi, I have read the thread named "Could not copy temporary files to the output directory" on this newsgroup. And I have the same symptoms on my machine. But I didn't find any solution suitable for...
2
by: Martin | last post by:
Hi, I have standard code that sends mail from an asp.net application. The application is running on a production web server. it uses the standard system.web.mail namespace. most of the time...
8
by: CJM | last post by:
I have a working web application (ASP) which links to an Oracle 10g DB via OO4O. I'm trying to port it to either of two test servers, but in fact, I can't get it to work with either - 'Unable to...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.