#1 03.05.10 08:36
[C++] Ошибка в программе
Код: cpp:
#include <stdio.h> #include <conio.h> #include <iostream> #include <fstream> #include <string> struct Automobile { char cFirma[40]; char cModel[10]; } sfaAutomobile; struct SparePart { char cName[40]; char cManufacturer[40]; char cPrice[40]; } sfaSparePart; struct SpareForAutomobile { struct Automobile sfaAutomobile; struct SparePart sfaSparePart; } sfaSpareForAutomobile; void main () { char cAnswer; bool SparePart; FILE* PointerToFile = fopen( "Spare for Automobile.txt", "a+" ); printf( "You wish to order the spare part? 1 - yes, 0 - no\n" ); scanf( "%d", &SparePart ); if ( SparePart == true ) while ( SparePart == true ) { printf( "Automobile\n" ); fprintf( PointerToFile,"%s", "Automobile" ); printf( "Firma: " ); scanf( "%s", &sfaAutomobile.cFirma ); fprintf( PointerToFile, "%s", "\nFirma: " ); fprintf( PointerToFile, "%s\n", sfaAutomobile.cFirma ); printf( "Model: " ); scanf( "%s", &sfaAutomobile.cModel ); fprintf( PointerToFile, "%s", "Model: " ); fprintf( PointerToFile, "%s\n", sfaAutomobile.cModel ); printf( "Spare Part\n" ); fprintf( PointerToFile, "%s", "Spare Part" ); printf( "Name: " ); scanf( "%s", &sfaSparePart.cName ); fprintf( PointerToFile, "%s", "\nName: " ); fprintf( PointerToFile, "%s\n", sfaSparePart.cName ); printf( "\Manufacturer: " ); scanf( "%s", &sfaSparePart.cManufacturer ); fprintf( PointerToFile, "%s", "Manufacturer: " ); fprintf( PointerToFile, "%s\n", sfaSparePart.cManufacturer ); printf( "Price: " ); scanf( "%s", &sfaSparePart.cPrice ); fprintf( PointerToFile, "%s", "Price: "); fprintf( PointerToFile, "%s\n", sfaSparePart.cPrice ); printf( "You wish to order the spare part? 1 - yes, 0 - no\n" ); scanf( "%d", &SparePart ); if( SparePart == false ) { fclose( PointerToFile ); break; } } std::string tmp; std::ifstream in("Spare for Automobile.txt"); while( std::getline( in, tmp ) ) std::cout << tmp << '\n'; in.close(); _getch(); }
Аааа, почему в конце завершения программы выдаёт ошибку?!
И ещё такой вопрос, как сделать чтобы в файл записывал только данные а выводил вместе с тем что я записываю сейчас?
Offline
#4 03.05.10 14:23
Re: [C++] Ошибка в программе
Укроп написал(а):
компилятор posix как бы нам подсказывает
./ex.cpp:33: warning: format ‘%d’ expects type ‘int*’, but argument 2 has type ‘bool*’
./ex.cpp:41: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char (*)[40]’
./ex.cpp:45: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char (*)[10]’
./ex.cpp:52: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char (*)[40]’
./ex.cpp:55: warning: unknown escape sequence '\M'
./ex.cpp:56: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char (*)[40]’
./ex.cpp:60: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char (*)[40]’
./ex.cpp:65: warning: format ‘%d’ expects type ‘int*’, but argument 2 has type ‘bool*’
Это не я бляяя...
Offline

