#include "replace.h"
#define PARAM_COUNT 5
using namespace std;
int main(int argc, char **argv)
{
if(PARAM_COUNT != argc) {
cout << "Invalid count of parameters" << endl;
return 1;
}
ifstream fin(argv[1]);
ofstream fout(argv[2]);
if(!fin) {
cout << "Can't open the input file" << endl;
return 2;
}
if(!fout) {
cout << "Can't open the output file" << endl;
return 3;
}
Replace::replace_strings(fin, fout, argv[3], argv[4]);
fin.close();
fout.close();
return 0;
}
#include <fstream>
#include <iostream>
#include <string>
namespace Replace
{
using namespace std;
void replace_strings(ifstream in, ofstream out, string what, string repl);
}
#include "replace.h"
namespace Replace
{
using namespace std;
void replace_strings(ifstream in, ofstream out, string what, string repl)
{
int pos = 0;
string buffer;
getline(in, buffer, '\0');
cout << buffer << endl;
cout << "String length: " << buffer.length() << endl;
while((pos = buffer.find(what)) != string::npos) {
buffer.replace(pos, what.length, repl);
}
cout << buffer << endl;
cout << "String length: " << buffer.length << endl;
}
}
#include <stdio.h>
#include <stdlib.h>
typedef struct List List;
struct List {
int value;
List *next;
};
int emptyList(List *item)
{
return (item->next == NULL) ? 1 : 0;
}
void printList(List *item)
{
List *q = item;
if(emptyList(item))
{
printf("Список пуст!\n");
} else {
while(q->next != NULL)
{
printf("%d, ", q->value);
q = q->next;
}
printf("\n");
}
}
int main(int argc, char* argv[])
{
int act;
List *head = NULL;
printf("Выберите действие:\n1. Вывод списка\n2. Добавить элемент в список\n0. Выйти из программы\n->");
scanf("%d", &act);
printf("%d\n", act);
switch(act)
{
case 1:
printf("+");
printList(head);
break;
}
return 0;
}
Как в данном случае я должен оповестить контроллер?
И что делать в main, если контроллер — отдельный класс и желательно сделать для каждого окна свой контроллер?