Here is the code
#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<pthread.h>
typedef struct std_thread
{
char name[20];
int hallno;
int empid;
char dept[5];
}std[5];
void *print(void *args)
{
struct std_thread *data=(struct std_thread *)args;
printf("My thread id is %ld\n",pthread_self());
printf("Thread %d is executing\n",args);
printf("Name\tHall No\tEmployee ID\tDepartment\n");
printf("--------------------------------------------------------");
printf("%s\t%d\t%d\t%s\n",data->name,data->hallno,data->empid,data->dept);
}
int main()
{
pthread_t th[5];
int empid=2020;
int hall=1;
char dept[2]="IT";
char *names[]={"dinesh","vignesh","pradeep","prasath","mohan"};
int t;
int i;
int status;
for(i=0;i<5;i++)
{
std[i].name=names[i]; //Getting error from this line
std[i].hallno=hall; //Error at this line
hall++;
std[i].empid=empid; //Error at this line
empid++;
std[i].dept=dept; //Error at this line
status=pthread_create(&th[i],NULL,print,(void *)&std[i]);
if(status)
{
printf("Error creating threads\n");
exit(0);
}
}
pthread_exit(NULL);
}
While compiling this code, I'm getting "syntax error before '[' token". What is the reason for this?