Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within C / C++
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
C / C++
malloc undeclared error in simple linked list
Punit Jain
Ranch Hand
Posts: 1143
5
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello,
i am trying to create a simple linked list, but i m getting one error there, below is my code:
#include <stdio.h> #include <conio.h> struct link { int info; struct link *next; }; int i; struct link *start = NULL; void createLinkList(struct link*); void displayLinkList(struct link*); /* Create the List */ void createLinkList(struct link *node) { char ch; printf("Enter choice n for exit"); ch = getchar(); i=0; while(ch!='n') { printf("\n Input the Node %d",i+1); scanf("%d",&node->info); node->next = (struct link*)malloc(sizeof(struct link)); node = node->next; node->next = start; i++; printf("Input Choice n for break"); ch = getchar(); } } /* Display the List */ void displayLinkList(struct link *node) { printf("\n Values of the entered node are as follows"); while(node) { printf(" %d",node->info); node = node->next; } } int main() { struct link *node = (struct link*)malloc(sizeof(struct link)); createLinkList(node); displayLinkList(node); getch(); return 0; }
Error is:
24 G:\c projects\linkedlist\SimpleLinkedList.cpp `malloc' undeclared (first use this function) 45 G:\c projects\linkedlist\SimpleLinkedList.cpp `malloc' undeclared (first use this function)
Punit Jain
Ranch Hand
Posts: 1143
5
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
actually i wan not including the library file #include<stdlib.h>, therefore the error was.
but now i have included and the error is gone, but one got more error..
24 G:\c projects\linkedlist\HeaderLinkedList.cpp [b]expected primary-expression before "struct"[/b]
Punit Jain
Ranch Hand
Posts: 1143
5
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
okay....
solved...
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Accurately detecting 64 bit Windows architecture
fgets and fscanf
Local call involves pass-by-reference
C2143 error and I can't find it
not able to call my header file
More...