Function problem

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 #include <stdio.h>
#include <stdlib.h>

typedef struct node {
    char author[30];
    char title[50];
    int year;
    struct node *next;
} NODE;

NODE* insert_intoDB() {
    NODE* first = NULL;
    NODE* current;
    char bool = 'y'; 
    while (bool == 'y') {
        if (bool == 'y') {
            if (first == NULL) {
                first = current = (NODE*) malloc(sizeof (NODE));
                printf("Title:");
                scanf("%s", current->title);
                while (getchar() != '\n');
                printf("Author:");
                scanf("%s", current->author);
                while (getchar() != '\n');
                printf("Year:");
                scanf("%d", &current->year);
                while (getchar() != '\n');
                current->next = NULL;
            } else {
                NODE* new = (NODE*) malloc(sizeof (NODE));
                printf("Title:");
                scanf("%s", new->title);
                while (getchar() != '\n');
                printf("Author:");
                scanf("%s", new->author);
                while (getchar() != '\n');
                printf("Year:");
                scanf("%d", &new->year);
                while (getchar() != '\n');
                new->next = current->next;
                current->next = new;
                new = current;
            }
            printf("Insert next record y/n:");
            bool = getchar();
        } else {
            break;
        }
    }

    return first;
}

void print_Data(NODE* first) {
    NODE* ptr = first;
    while (ptr != NULL) {
        printf("Title:%s Author:%s Year:%d\n", ptr->title, ptr->author, ptr->year);
        ptr = ptr->next;
    }
}

int count_books(NODE* first, int year) {
    int counter = 0;
    NODE* temp = first;
    while (temp != NULL) {
        if (year == temp->year) {
            counter++;
        }
        temp = temp->next;
    }
    return counter;
}

int main(int argc, char** argv) {


    NODE* first = insert_intoDB();
    print_Data(first);
    printf("%d",count_books(first,1994));
    return (EXIT_SUCCESS);
}


What is your question?

Syntax errors (if C++):
Line 14-16: bool is a C++ reserved word. You can't use it as a variable name in a C++ program.
line 30: new is also a C++ reserved word.

This looks like a C only program. Make sure "Compile C as C++" option is turned off in your compiler.

sorry some stupid connection mistake ...exactly that!
i wrote that as a code in netbeans, when i compiled it, its works, but when i try compil that code on our server a lots of errors start bugging me... i dont relised that c++ compile is turn on ...
thanks :)
Topic archived. No new replies allowed.