0

How to solve this error in c [Error] expected primary-expression before '.' token please check my code

#include <stdio.h> #include <string.h> #define size 100 typedef struct StudentData{ char name[size]; char surname[size]; int std_ID; char nationality[size]; char department[size]; int year; float CGPA; char gender; }s1, s2; int main () { strcpy(s1.name, "Albert"); strcpy(s1.surname, "Paul"); s1.std_ID = 12345678; strcpy(s1.department, "Software Engineering"); s1.year = 1; s1.CGPA = 1.91; s1.gender = 'M'; printf("S1 full name is %c %c \n", s1.name, s1.surname); printf("His std_ID is %c and gender is %c \n", s1.std_ID, s1.gender); printf("his dep. is %c \n", s1.department); printf("His CGPA is %f, and year is %d \n", s1.CGPA, s1.year); return 0; }

16th May 2021, 10:34 PM
gedeon mubenga
gedeon mubenga - avatar
1 Answer
+ 1
The syntax of the typedef is wrong. try: ... typedef struct { ... //attributes ... } <struct_name_here>; i changed yours to define a type called student, then made two student variables: s1 & s2 EDIT: then deleted the second variable because it was unused Also, look at your string formatting. You are looking for %c 'characters' but passing %s 'strings' https://code.sololearn.com/cu5kZ6gQdpJ0/?ref=app
16th May 2021, 11:11 PM
Slick
Slick - avatar