#include<stdio.h>
#include<conio.h>
struct adj_node
{
char nam;
struct adj_node *adj_next;
};
struct node
{
char name;
struct adj_node *down;
struct node *next;
};
struct node * gins(struct node *);
struct node * lins(struct node *);
main()
{
int n,i,j;
char c,r;
struct node *g,*t;
g=malloc(sizeof(struct node));
g->next=NULL;
g=gins(g);
g=lins(g);
getch();
}
struct node * gins(struct node *a)
{
char c;
do
{
printf("n enter vertex else a spacen");
scanf("%c",&c);
fflush(stdin);
if(c!=' ')
{
a=a->next;
a=malloc(sizeof(struct node));
a->name=c;
a->next=NULL;
}
}while(c!=' ');
return a;
}
struct node * lins(struct node *a)
{
char c;
do
{
a=a->next;
do
{
printf("n is there any edge incedented on vertex %c Y or N n",a->name);
scanf("%c",&c);
fflush(stdin);
if(c=='Y')
{
a->down=malloc(sizeof(struct adj_node));
printf("n enter the other vertex of the edge incedented on %cn ",a->name);
scanf("%c",&a->down->nam);
fflush(stdin);
a->down->adj_next=NULL;
a->down=a->down->adj_next;
}
else
{
a->down=NULL;
}
}while(c!='N');
a=a->next;
}while(a->next!=NULL);
return a;
}
optimus_prime_1
-6
Newbie Poster
Recommended Answers
Jump to PostThe error you're getting typically means there's an access violation. Access violations are typically caused by invalid pointers, so your first line of attack should be to step through your code in a debugger and keep a close watch on your pointers to make sure that they're valid at any …
Jump to PostNo offense, but while I could do your debugging for you and tell you exactly what the problem is and how to fix it, you wouldn't learn jack from that. Given that this is the first of many, many, many access violations you're sure to encounter, you'd benefit greatly from …
Jump to Postsome one correct my program and let me continue my execution .............
I did take a look at the code, and you're clearly dereferencing null pointers. Here's one example:
a=a->next; a=malloc(sizeof(struct node)); a->name=c; a->next=NULL;
The first
a = a->next
makesa
a …
All 10 Replies
optimus_prime_1
-6
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
optimus_prime_1
-6
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
optimus_prime_1
-6
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
optimus_prime_1
-6
Newbie Poster
deceptikon
commented:
Maybe it's a language barrier, but lots of rude and presumptuous remarks in this post.
-2
optimus_prime_1
-6
Newbie Poster
optimus_prime_1
-6
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.