Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:12:22+00:00 2026-06-11T21:12:22+00:00

I am trying to compile my program in C, and these are the errors

  • 0

I am trying to compile my program in C, and these are the errors I get:
(Please note that I am a beginner at this language.)

Excer3.c: In function `addstudent’:

Excer3.c:50: error: `student' undeclared (first use in this function)
Excer3.c:50: error: (Each undeclared identifier is reported only once
Excer3.c:50: error: for each function it appears in.)
Excer3.c:50: error: parse error before "newS"
Excer3.c:50: error: `newS' undeclared (first use in this function)
Excer3.c:50: error: parse error before ')' token
Excer3.c:52: error: `studentName' undeclared (first use in this function)
Excer3.c: At top level:
Excer3.c:59: error: parse error before '*' token
Excer3.c: In function `readdb':
Excer3.c:70: error: `students' undeclared (first use in this function)
Excer3.c:70: warning: passing arg 2 of `addstudent' makes integer from pointer without                 a cast

My code looks like this. The function doesn’t recognize the arguments it was given. :

#include <stdio.h>

struct student {
int studentnumber;
char* Name;
struct student* next;
};

struct teacher {
int teachernumber;
char* Name;
struct teacher* next;
};

struct course {
struct teacher teachers[5];
struct student students[50];
int semesternumber;
struct course* next;
};

int readline(char s[],int lim)
{
  int c, i;
  for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
    s[i] = c;
  if (c == '\n') {
    s[i] = c;
    ++i;
  }
  s[i] = '\0';
  return i;
}

int addstudent (struct student* prev, int studentnumber, char* studentname)
{
if (!(prev==NULL))
  student newS = (student*)malloc(sizeof(student));
  newS->studentnumber = studentnumber;
  newS->firstname = strdup(studentName);
  newS->next = NULL;
  prev->next=newS;

  return 1;
}

int readdb(student* students)
{
char line[200];
int* studentnumber,coursenumber,teachernumber,semesternumber;
char studentname[100],teachername[100],coursename[100];

while(readline(line,200) > 0)
{
if(sscanf(line, "S %d %s", &studentnumber, studentname)==2)
{
 printf("Student. \n\tStudent number: %d, \n\tFirst name: %s\n", studentnumber,  
studentname);
 addstudent(students,&studentnumber,studentname);
 }
else if(sscanf(line, "C %d %s %d", &coursenumber, coursename , &semesternumber)==3)
   printf("Course. \n\tCourse number: %d \n\tCourse name: %s \n\tSemester: %d\n",   
coursenumber, coursename, semesternumber);
else if(sscanf(line, "E %d %d", &studentnumber, &coursenumber)==2)
printf("Enrolment. \n\tStudent number: %d, \n\tCourse number: %d\n", studentnumber, 
coursenumber);
else if(sscanf(line, "T %d %s", &teachernumber, teachername)==2)
 printf("Teacher. \n\tTeacher number: %d, \n\tFirst name: %s\n", teachernumber,  
teachername);
else if(sscanf(line, "A %d %s", &teachernumber, &coursenumber)==2)
 printf("Assignment. \n\tTeacher number: %d, \n\tCourse number: %d\n", teachernumber,
coursenumber);
}

}


int main () 
{
struct student* students = NULL;

readdb(&students);
return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:12:23+00:00Added an answer on June 11, 2026 at 9:12 pm

    The existing answers are correct: student isn’t a type name in your program at the moment, but struct student is. You’re already using this correctly, so just make it consistent.

    At the risk of digressing into code review territory, addstudent still won’t do what you want.

    int addstudent (struct student* prev, int studentnumber, char* studentname)
    {
        if (!(prev==NULL))
            student newS = (student*)malloc(sizeof(student));
        newS->studentnumber = studentnumber;
        newS->firstname = strdup(studentName);
        newS->next = NULL;
        prev->next=newS;
    
        return 1;
    }
    

    so this is trying to append to the end of a linked list, which is fine, but there are some errors:

    • the newS declaration should be struct student *newS = malloc(sizeof(*newS));

      1. we fix the struct name your compiler was complaining about
      2. malloc returns a pointer, so newS has to be a pointer as well
      3. p = malloc(sizeof(*p)) is a common idiom that avoids bugs when you change the type of p in the future, but forget to edit the sizeof expression
    • you’re currently declaring newS only inside the scope of the if statement – this means the following lines which refer to newS won’t compile, as they can’t see that variable. We can extend the scope with braces like so: if (prev) { ... } return 1;

    • newS->next is always set to NULL, so if prev->next already has a value, it’s discarded. This means your linked list can only ever be one student long. If you want to keep your list linked together, it should be

      newS->next = prev->next;
      prev->next = newS;
      
    • you’re mixing up struct student ** (which is the type passed in readdb(&students)) and struct student * … you need to figure out which you want, and stick with it. The current addstudent code will only work if you have a struct student instance (not a pointer) with next initialized to NULL as the head of your list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i get 2 linker errors when trying to compile my program which includes these
I'm trying to compile an example program that links to the shared library produced
when I'm trying to compile my c program it gives me this error warning:
I'm trying to compile this simple program to start learning how to use timers:
I'm trying to compile a Windows C++ program in g++. This is what I
I have a python program I wrote that I am trying to compile with
I am trying to compile Qt 4.7.4, but I always get this error: mt.exe:
In trying to compile this program: namespace MyNamespace { template<typename T> class Test {
I have the following code that calls the function uint32_pack. This program compiles with
I'm trying to compile a C program, with these headers: http://pastebin.com/SppCXb0U , on Ubuntu.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.