int fflush(FILE* qpStream);
#include <cstdio> int main() { char* cpFileName = "XoaX.txt"; FILE* qpFile = fopen(cpFileName, "r+" ); // Verify that the file was opened. if (!qpFile) { printf("Could not open the file %s\n", cpFileName); return 1; } // This writes over the first four bytes fputs("XoaX", qpFile); // Without this flush, fgets writes garbage to our file fflush(qpFile); char caBuffer[10]; // Read the remaining bytes of the file into a buffer fgets(caBuffer, 5, qpFile); printf("Read in: %s\n", caBuffer); int iResult = ferror(qpFile); if (iResult != 0) { printf("Reading Error: %i\n", iResult); return 1; } fclose(qpFile); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.