Thanks. But I have another function witch loads the struct value from the line of text file.
Code:
int load_struct() //this function loads structs element from the file.{
int x=0;
int i=count(x);
struct student line[i];
char file_line[100];
char* line_parts;
FILE * fp; // file opens here.
if ((fp = fopen ("file.txt", "r")) != NULL)
{
while (x<i) {
fgets(file_line,100,fp); // gets line from the file.
line_parts = strtok(file_line,",");
line[x].st_id = atoi(line_parts);
line_parts = strtok(NULL, ",");
strcpy(line[x].st_name,line_parts);
line_parts = strtok(NULL, ",");
line[x].st_age = atoi(line_parts);
line_parts = strtok(NULL, ",");
strcpy(line[x].st_dep,line_parts);
line_parts = strtok(NULL, ",");
line[x].st_grade = atoi(line_parts);
x++;
}
}
fclose(fp);
return 0;
}
Now I have to use these value in modify_data function. I only call load_struct and modify_data function in the main?
Sorry I am new and not doing much in the pointer. Thanks again.