Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fileGet (const fname[], const key[]) {
- new buf[255], name_row[32], name_values[128], File:fget = fopen (fname, io_read);
- if (!fget) {
- print ("Function [fileGet]: Nie mozna otworzyc pliku.");
- fclose (fget);
- }
- while (fread (fget, buf)) {
- printf (buf);
- file_stripNewline (buf);
- if (sscanf (buf, "p<=>s[32]s[128]", name_row, name_values)) continue;
- if (!strcmp (name_row, key, true)) {
- file_stripNewline (name_values);
- fclose (fget);
- return name_values;
- }
- }
- fclose (fget);
- return name_values;
- }
- file_stripNewline (string[]) {
- new length = strlen (string);
- if (!string[0]) return;
- if ((string[length - 1] == '\n') || (string[length - 1] == '\r')) {
- string[length - 1] = 0;
- if (!string[0]) return;
- if ((string[length - 2] == '\n') || (string[length - 2] == '\r')) string[length - 2] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment