little_greg Posted May 19, 2009 Report Share Posted May 19, 2009 Помогите разобраться, что не так! ОШИБКИ: 11 D:\main.cpp cannot convert `bool' to `FILE*' in assignment 351 C:\Dev-Cpp\include\stdlib.h too few arguments to function `void exit(int)' 14 D:\main.cpp at this point in file #include <cstdlib> #include <iostream> #include <fstream> #include <stdio.h> using namespace std; int main(int argc, char *argv[]) { FILE *fp; char letter; if((fp=fopen("MYFILE","w")==NULL)) { puts("Nevozmozhno otkryt fail"); exit(); } do { letter=getchar(); fputc(letter,fp); } while(letter!='\r'); fclose(fp) system("PAUSE"); return EXIT_SUCCESS; } Link to comment Share on other sites More sharing options...
Darhazer Posted May 19, 2009 Report Share Posted May 19, 2009 (edited) if((fp=fopen("MYFILE","w")==NULL)) Должно быть: if( (fp=fopen("MYFILE","w")) == NULL ) :) Edited May 19, 2009 by Darhazer Link to comment Share on other sites More sharing options...
little_greg Posted May 20, 2009 Author Report Share Posted May 20, 2009 Спасибо. Я уже сам заметил))) Link to comment Share on other sites More sharing options...
little_greg Posted May 20, 2009 Author Report Share Posted May 20, 2009 Почему, программа не завершает свою работу после нажатия N или n, а при вводе другого символа появляются сразу две строки: Vvedite imya Zhelaete vvesti drugoe imya? #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { FILE *fp; char flag; char name[20]; if((fp=fopen("MYFILE","w"))==NULL) { puts("Nevozmozhno otkryt fail"); system("PAUSE"); exit(0); } flag='y'; while((flag!='N')||(flag!='n')) { puts("Vvedite imya"); gets(name); fputs(name,fp); fputs("\n",fp); puts("Zhelaete vvesti drugoe imya?"); flag=getchar(); putchar('\n'); } fclose(fp); system("PAUSE"); return EXIT_SUCCESS; } Link to comment Share on other sites More sharing options...
Тролль Posted May 21, 2009 Report Share Posted May 21, 2009 little_greg: При вводе символа вводится и символ перевода строки, при вводе его надо отбрасывать. Конкретно, вместо flag=getchar(); нужно flag=getchar(); getchar(); Кроме того, в любом случае ты никогда не выйдешь из цикла. Условие ((flag!='N')||(flag!='n')) всегда верно. Правильно будет (flag!='N' && flag!='n') Link to comment Share on other sites More sharing options...
little_greg Posted May 22, 2009 Author Report Share Posted May 22, 2009 Спасибо! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now