I'm coding in C language and can't find out what is the error.It keeps telling me that First: in this line
temp = (Node*) malloc(sizeof(struct Node));
the Node
is undeclared and first use is in this function.but I think I've declared it before.
Second: in the same line
"expected expression before ')' token"
it points to the (Node*)
and Third :
"expected declaration or statement at end of input."
while it points to the closed }
of main.
For the first one I've searched and found out it's because of C89 and I have to declare all the variables at the top of my functions.I did but the error is still there.
here's my code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
struct Node{
int data;
struct Node* next;
};
struct Node* head;
void Add(int x){
struct Node* temp;
temp = (Node*) malloc(sizeof(struct Node));
temp -> data = x;
temp -> next = head;
head = temp;
}
void print(){
struct Node* temp;
temp = head;
printf("List is:");
while(temp != NULL){
printf(" %s",temp -> data);
temp = temp -> next;
}
int main(int argc, char **argv)
{
head = NULL;
Add(3);
print();
return 0;
}
I'm trying to use a linked list.