Advertisement
QuantumWarpCode

Broken C++ Read File Code

Jul 14th, 2015
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Data types
  2. #include <string>
  3. #include <cstring>
  4. #include <tchar.h>
  5.  
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <vector>
  9.  
  10. //Streams
  11. #include <stdio.h>
  12. #include <cstdio>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <sstream>
  16.  
  17. #include <fstream>
  18.  
  19. char* readShader(char* filename) {
  20.     FILE* infile;
  21.     int tempint;
  22.     tempint = fopen_s(&infile, filename, "r");
  23.     if (tempint != 0) {
  24.         std::cout << "Error " << tempint << " when reading file " << filename << std::endl;
  25.         return "Error reading file.";
  26.     }
  27.  
  28.     boolean loop = true;
  29.     int loops = 0;
  30.     char* text = "";
  31.     char temptext[2];
  32.     int index = 0;
  33.  
  34.     while (loop) {
  35.         fgets(temptext, 2, infile);
  36.         //std::cout << temptext;
  37.         if (temptext != NULL && std::feof(infile) != 1) {
  38.  
  39.             //this next section is what causes errors
  40.             if (loops == 0) {
  41.                 //strcpy_s(text, 2, temptext);
  42.                 text[0] = temptext[0];
  43.                 std::cout << text;
  44.             }
  45.             else {
  46.                 //strcat_s(text, 2, temptext);
  47.                 text[1] += temptext[1];
  48.                 std::cout << text;
  49.             }
  50.             loops++;
  51.         }
  52.         else {
  53.             loop = false;
  54.         }
  55.  
  56.     }
  57.     fclose(infile);
  58.     return text;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement