Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- enum
- {
- MAXN = 1000
- };
- typedef struct el
- {
- char type;
- int key;
- char s[100 + 1];
- } el;
- el t[MAXN][20];
- char buff[20 * 101];
- int main(void)
- {
- FILE* in = fopen("input.txt", "r");
- FILE* out = fopen("output.txt", "w");
- int n;
- fscanf(in, "%d\n", &n);
- int str = 0;
- while (fgets(buff, 20*101, in))
- {
- int it = 0;
- int col = 0;
- while (buff[it] != '\0')
- {
- while ((buff[it] != '\0') && (buff[it] != ';') && (buff[it] != '\n'))
- ++it;
- int curr = it - 1;
- _Bool isnum = 1;
- int cnt = 0;
- while ((curr >= 0) && (buff[curr] != ';'))
- {
- if ((buff[curr] < '0' || '9' < buff[curr]) && (buff[curr] != ' ') && (buff[curr] != '\n'))
- isnum = 0, ++cnt;
- --curr;
- }
- ++curr;
- if ((!isnum) && (cnt == 1) && (buff[curr] == '-'))
- isnum = 1;
- if (isnum)
- {
- int sum = 0;
- while (buff[curr] == ' ')
- ++curr;
- while ((curr < it) && (buff[curr] != ' '))
- {
- sum = sum * 10 + buff[curr] - '0';
- ++curr;
- }
- t[str][col].type = 'i';
- t[str][col].key = sum;
- }
- else
- {
- t[str][col].type = 's';
- int j = 0;
- while (buff[curr] != '"')
- ++curr;
- ++curr;
- while ((curr < it) && (buff[curr] != '"'))
- {
- t[str][col].s[j] = buff[curr];
- ++curr;
- ++j;
- }
- t[str][col].s[j] = '"';
- ++j;
- t[str][col].s[j] = '\0';
- }
- ++it;
- ++col;
- }
- ++str;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment