Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>Start by reading a line by line using <code>fgets()</code>. </li> <li>If the first character is a digit then use <code>strtol</code> to convert to number. </li> <li>Use <code>strtok</code> to break the line - split the string into tokens delimited by dots and spaces</li> </ol> <p>EDIT: Please find the implementation as described in the above steps to read the file into structure. Idea is to read each line using <code>fgets()</code> and parse it using <code>strtok</code> at required delimiters etc., </p> <pre><code> struct date { int da_year; int da_month; int da_day; }; struct studenti { int Nr; char name[25]; char surname[25]; struct date dzd; char dzimums; } students[N]; int main() { FILE *fails_st; char line[100]; char *ptk; char * end; int i; fails_st = fopen("studenti.txt", "r"); for(i=0; i &lt; N &amp;&amp; fgets(line, sizeof(line), fails_st) != NULL; i++) { students[i].Nr = strtol(line, &amp;end, 10); ptk = strtok(line, " "); ptk = strtok(NULL, " "); strcpy(students[i].name, ptk); ptk = strtok(NULL, " "); strcpy(students[i].surname, ptk); ptk = strtok(NULL, "."); end = (ptk + strlen(ptk)); students[i].dzd.da_day = strtol(ptk, &amp;end, 10); ptk = strtok(NULL, "."); end = (ptk + strlen(ptk)); students[i].dzd.da_month = strtol(ptk, &amp;end, 10); ptk = strtok(NULL, " "); end = (ptk + strlen(ptk)); students[i].dzd.da_year = strtol(ptk, &amp;end, 10); ptk = strtok(NULL, " "); students[i].dzimums = *ptk; } fclose(fails_st); printf("Student list\n"); for(i=0; i&lt;N; i++) printf("%d. %s %s %d.%d.%d %c\n", students[i].Nr, students[i].name, students[i].surname, students[i].dzd.da_day, students[i].dzd.da_month, students[i].dzd.da_year, students[i].dzimums); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload