AXV09

Untitled

May 1st, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. fileGet (const fname[], const key[]) {
  3. new buf[255], name_row[32], name_values[128], File:fget = fopen (fname, io_read);
  4. if (!fget) {
  5. print ("Function [fileGet]: Nie mozna otworzyc pliku.");
  6. fclose (fget);
  7. }
  8. while (fread (fget, buf)) {
  9. printf (buf);
  10. file_stripNewline (buf);
  11. if (sscanf (buf, "p<=>s[32]s[128]", name_row, name_values)) continue;
  12. if (!strcmp (name_row, key, true)) {
  13. file_stripNewline (name_values);
  14. fclose (fget);
  15. return name_values;
  16. }
  17. }
  18. fclose (fget);
  19. return name_values;
  20. }
  21.  
  22. file_stripNewline (string[]) {
  23. new length = strlen (string);
  24. if (!string[0]) return;
  25. if ((string[length - 1] == '\n') || (string[length - 1] == '\r')) {
  26. string[length - 1] = 0;
  27. if (!string[0]) return;
  28. if ((string[length - 2] == '\n') || (string[length - 2] == '\r')) string[length - 2] = 0;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment