Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. FILE* fp = fopen(argv[1], "r");
  2. if (fp == NULL) {
  3. printf("Cannot open filen");
  4. return 1;
  5. }
  6.  
  7. //Begin copying file using fgetc
  8. int c;
  9. while ((c = fgetc(fp)) != EOF) {
  10. for (int i = 0; i < PUZZLE_SIZE; ++i) {
  11. for (int j = 0; j < PUZZLE_SIZE; ++j) {
  12. if (c != -38) { //-38 is newline
  13. //puzzle is a global array of ints
  14. puzzle[i][j] = c - 48; //handles ASCII to int (1-9) conversion
  15. }
  16. }
  17. }
  18. }
  19. fclose(fp);
  20.  
  21. 534678912
  22. 672195348
  23. 198342567
  24. 859761423
  25. 426853791
  26. 713924856
  27. 961537284
  28. 287419635
  29. 345286179
  30.  
  31. for (int i = 0; i < PUZZLE_SIZE; ++i)
  32. for (int j = 0; j < PUZZLE_SIZE; ++j) {
  33. c = fgetc(fp);
  34. if (c == 'n')
  35. c = fgetc(fp); // get a new char if we hit a newline
  36. puzzle[i][j] = c - `0`;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement