scanf is quite a powerful thing in capable hands. Here is a working example (for input data)
#include <stdio.h> int main(void) { int id; char name[100]; char surname[100]; int day, month, year; int data[4]; int x = scanf("%i . %s %s %*[ \t|]%i.%i.%i %*[ |] %i %i %i %i",&id, name, surname, &day, &month, &year, &data[0], &data[1], &data[2], &data[3]); printf("x = %d\n", x); // выведем, сколько распарсилось полей // и сами поля printf("id = %i\nname = %s\nsurname = %s\ndate %i %i %i\n", id, name, surname, day, month, year); printf("data = %i %i %i %i\n", data[0], data[1], data[2], data[3]); return 0; }
The string "formatting" (or all the same "formatted reading"?) Is quite complicated, but simple. Let's break it into pieces
`%i .` прочитать число и точку. Тут все просто и по документации. `%s %s` прочитать два слова. Слова разделяются пробелами. `%*[ \t|]` это странная строка, которая говорит, читай любыме символы в скобках (пробел, табуляция и палочка (пайп)) процент-звездочка в начале говорит "читай, но не вноси в переменную". `%i.%i.%i` тут все просто - прочитать 3 целых числа через точку. `%*[ \t|]` тут аналогично. `%i %i %i %i` здесь снова все просто - 4 целых числа.
the construction with square brackets is a bit specific and earlier its compilers did not support. But gcc supports exactly, and vs seems to be the same. But you need to check.
fscanf(table, "template", data[i].name, data[i].age, ...)and then there will be no "rubbish" at the output - Herrgott