well, i should have to pass up my assignment soon, but there's a lot of syntx error that could found. could you help me about those syntax ?? thanks for help ...
Code:
================= struct pointer ==================
void add (NODE *ptr, int v1, int v2);
#include <stdio.h>
typedef struct
{
int a;
int b;
int ans;
} NODE;
int main ()
{
NODE start;
int num1, num2;
printf ("enter 2 num > ");
scanf ("%d %d", num1 ,num2);
add (&start, num1, num2);
return 0;
}
void add (NODE *ptr, int v1, int v2)
{
ptr->a = v1;
ptr->b = v2;
ptr->ans = v1 + v2;
printf("the ans is %d\n\n", ptr->ans);
}
=============linked list ====================
#include <stdio.h>
#include <stdlib.h>
void printvalue (NODEPTR *sptr);
void insertvalue (NODEPTR *sptr, char value);
struct nodelist{
char data;
struct nodelist *nextptr;
};
typedef struct nodelist NODE;
typedef NODE *NODEPTR;
int main ()
{
// local definition
NODEPTR start = NULL;
char value;
char again;
do {
printf ("Please enter the value (char) > ");
scanf ("%c", &value);
insertnode (&start, value);
printnode (&start);
printf ("\nInsert again ? > ");
scanf ("%c", &again);
} while (toupper (again) == 'Y')
return 0;
}
void insertvalue (NODE *sptr, char value)
{
NODEPTR newptr;
NODEPTR cptr;
NODEPTR pptr;
newptr = (NODE *)malloc (sizeof (NODE));
if (!newptr) {
printf ("ERROR ... no memory available!")
exit (100);
}
else {
newptr->data = value;
newptr->nextptr = NULL;
cptr = *sptr;
while (value >= cptr->data && cptr != NULL)
{
pptr = cptr;
cptr = cptr->nextptr;
}
pptr->nextptr = newptr;
newptr->nextptr = cptr;
}
}
void printvalue (NODE *sptr)
{
NODEPTR cptr;
printf ("\n\nThe result is...\n\n");
for (cptr = *sptr ; cptr != NULL ; cptr = cptr->nextptr)
{
printf ("%d",cptr->data);
printf (" -> ");
}
printf ("NULL");
}
Code tags added by Hammer