I might have just fixed it by changing this line: [Items*new=(Items*)malloc(sizeof(Items*));} to
Items*new=(Items*)malloc(sizeof(Items));
Could someone explain how exactly my code is...
Type: Posts; User: Adam Rinkleff
I might have just fixed it by changing this line: [Items*new=(Items*)malloc(sizeof(Items*));} to
Items*new=(Items*)malloc(sizeof(Items));
Could someone explain how exactly my code is...
I changed the code slightly:
new->loc=&a[currentarea]; printf("%s", new->name);
new->prev=NULL; printf("%s", new->name);
new->next=NULL; printf("%s", new->name);
If the name is...
I don't really know how to even begin solving this problem. Basically, I have a structure:
struct Items{
char*desc;
char*name;
char*behave;
struct Areas*loc;
struct Items*next;
Laserlight is the best programmer in the whole world!
Wow! They both work, hm. I'm not even sure why new = malloc(sizeof(*new)); would work, how does it know what the size of new is supposed to be, if it doesn't know its an area*? I guess I don't really...
I added the following line to the end of the for loop
if(i>1){printf("[[::%p::]]", new->prev->prev);}
This shows that the pointer value is switching to ox11 at the end of each pass. But...
I created a series of linked lists and then printed them. Notice that I touch new->prev one time, and I verify it has been set via printf at the end of the for loop. However, when I then print all...
Oh, I don't think I need the while(1) at all, its just not necessary.
This is what I want:
void printnode(Area*current){
printf("\n<%d||[%p]>: <%p|%p>\n", current->name, current,...
break; was only there because return; wasn't working. I can take the break out but nothing changes.
void printnode(Area*current){
while(1){
if(current->next==NULL){printf("[%p]", current->next); return;}
if(current->next!=NULL){printnode(current->next);}
}
}
In this while loop, as I...
oh... that might be it actually... thanks! ill have to try and see if i can fix it now.
I have this section of code. Basically it uses fgets to read from a file, and at the end it does this:
new->name=name;
a[currentarea].items=new; ...
struct Areas{
char desc[255];
char name[255];
struct Items*items;
int n,s,w,e,u,d;
};
struct Items{
char*desc;
I don't know, I thought I have defined these structs. The error seems to be that it isn't properly defined. I tried what itCbitC said, but the following still gives the same errors:
typedef...
I'm trying to make this basic 'MUD' style game to practice coding, the problem I was having was trying to have two structure types, each of which can contain a pointer to the other type. After I...
Thanks! The following seems to work just fine:
printf("Number: %s\n", new->number);
It should look like this:
---------------Top of the Screen------------------
Enter Command:
Instead I get:
In input(), system("clear") executes first in a while loop, and then add(); is called... however, before add(); finishes and returns to input(), system("clear"); is called again and executes in the...
Oh, I think I know...
I need:
strcpy(new->name, input);
:D
Why might this be: incompatible types in assignment
Here is my struct:
typedef struct{
char name[250];
char number[10];
} List;
Obviously, I just did, which is why I said it seemed a lot easier -- how about we assume that if I see a line of code, I do try it -- and if I hear about a function, I probably go and look it up......
Oh, I was trying *X, *p[0], but going back to post #10 -- why use memcpy at all if I can just use what AndrewHunter suggested?
That seems a lot easier, why then would I ever want to use memcpy instead of that?
I did try it:
incompatible type for argument 1 of `memcpy'
incompatible type for argument 2 of `memcpy'
sizeof(p[0]) is 35024, is that the size of the structure regardless of the values within it, or do those change?
Should I just do:
memcpy ( X, p[0], sizeof(p[0]));
?
Yah I guess that...