Suyog Dahal
Suyog Dahal

Reputation: 55

error: expected identifier or ‘(’ before ‘)’ token

I have created a function register to register the name from the standard input and put it into a file but it gives me error listed below. please help.

#include<stdio.h>
#include<string.h>
void register(){
    char* reg_names;
    printf("Please enter a username for registration: ");
    scanf("%s", &reg_names);
    printf("\n");
    FILE *fpointer;
    fpointer = fopen("registration.txt", "a+");
    if(fpointer == NULL){
        printf("Error connecting to the database. Check for corruption of the database.");
    }else{
        fprintf(fpointer, "%s\n", name);
        printf("User has been registered as %s", name);
        fclose(fpointer);
    }
}

int main(void){
    int registration;
    char* usr_names;
    char* registered;
    printf("***************** Welcome to The Library Management System ********************\n");
    printf("Enter the value \t1 if you have account or \t2 if you are new and have to register: \t");
    scanf("%d", &registration);
    if(registration == 1){
    printf("test");
    }else{
        register();
    }
    return 0;
}

I am getting

library.c:6:15: error: expected identifier or ‘(’ before ‘)’ token                                                                                            
 void register(){
               ^                                                                                                                                              
library.c: In function ‘main’:                                                                                                                                
library.c:32:12: error: expected identifier or ‘(’ before ‘)’ token                                                                                           
   register();

error while running the code. I am a beginner in C trying to get better knowledge of it.

Upvotes: 0

Views: 1111

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224310

register is a keyword in C. You cannot use it as an identifier. Pick a different name for your function.

Upvotes: 2

Related Questions