Top.Mail.Ru
Ответы

Ругается на 67 строку кода, хотя их всего 21. C++ (работа с файлами)

Ругается на 67 строку
File: f:\dd\vctools\crt\crtw32\stdio\fgetc.c
Line: 67
Expression: (stream != NULL)

#include "stdafx.h"
#include
#pragma warning (disable:4996)
int main() {
FILE* in = fopen("input.txt", "r");
FILE* out = fopen("output.txt", "w");
char space = 0;
short c;
while ((c = getc(in)) != EOF)
if (c == ' ') {
if (!space) {
space = 1;
putc(' ', out);
}
} else {
space = 0;
putc(c, out);
}
fclose(in);
fclose(out);
}

По дате
По рейтингу
Аватар пользователя
Профи
11лет

Так а если файлы не открылись?

надо так.

#include <errno.h>

FILE* in = fopen("input.txt", "r");
if (!in) {
fprintf(stderr, "Error opening file input.txt: %s\n", strerror(errno));
return errno;
}

FILE* out = fopen("output.txt", "w");
if (!out) {
fclose(in);
fprintf(stderr, "Error opening file output.txt: %s\n", strerror(errno));
return errno;
}

А дальше уже работать.

Вероятнее всего, эти файлы у вас рядом с исполняемой
прогой не лежат, вот и не находятся.

Источник: <noindex><a rel="nofollow" href="http://www.cplusplus.com/reference/cstring/strerro" target="_blank">http://www.cplusplus.com/reference/cstring/strerro</a></noindex>
Аватар пользователя
Просветленный
11лет

файлы-то заголовочные все заинклюдил? ) а то меня терзают смутные сомненья, что далеко не все... ))

Аватар пользователя
Ученик
11лет

Хоть все ( #include "stdafx.h"
#include
#include
#include
#include
#include ), оно ошибку вьідает все-равно



Видео по теме