What's the problem ? I can't find

Guys Hello put command fails.What's the reason?Can be a libraries ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include<conio.h>


void dosya_olustur(char[]);
void sifrele(char[]);
void cozumle(char[]);
void diz(void);
struct harf {
       char deger;
       int s_deger;
       }
       harf [26];
int main ()
{
    diz ();
    int x=0;
    char dosyaAdi[20];
    while(x)
    {
            cout<<"1 - dosya olusturma"<<endl;
            cout<<"2 - dosya sifreleme"<<endl;
            cout<<"3 - sifreli dosyayi acma"<<endl;
            cout<<"4 - cikis"<<endl;
            cin>>x;
            if(x==4) break;
            switch (x)
            {
                      case 1:
                           cout<<"olusturlacak dosyanin adini giriniz:"<<endl;
                           cin>>dosyaAdi;
                           dosya_olustur(dosyaAdi);
                           break;
                           case 2:
                                 cout<<"sifrelenecek dosyanin adini giriniz:"<<endl;
                                 cin>>dosyaAdi;
                                 sifrele(dosyaAdi);
                                 break;
                                 case 3:
                                      cout<<"sifre cozulecek dosyanin adini giriniz"<<endl;
                                      cin>>dosyaAdi;
                                      cozumle(dosyaAdi);
                                      break;
                                      default:
                                              cout<<"yanlis girdiniz..."<<endl;
                                              }
                                              }
                                              return 0;
                                              }
void diz()//harfleri siralama fonksiyonu
{
     char e='a';
     int a=0; int b=1;
     for(int i=0;i<26;i++)
     {
             harf[i].deger='e';
             harf[i].s_deger=b;
             e++; //ASCII
             b++;
             
             
             }
     }       
void dosya_olustur(char dosyaAdi[])// dosya olusturma fonk
{
     char metin[100];
     ofstream m_dosya;
     m_dosya.open(dosyaAdi);
     if(m_dosya.fail())
     {
                       cout<<"dosya acılamadi!";
                       exit(1);
                       
                       }
                       cout<<"dosya acildi verileri yazabilirsiniz."<<endl;
                       m_dosya.close();
                       
     }             
void sifrele(char dosyaAdi[])//sifreleme
{
     char e,x,sifre[8];
     int i,j,k,s,sfr[8];
     ifstream dosya;
     dosya.open(dosyaAdi);
     if(dosya.fail())
     cout<<"dosya acilamadi!"<<endl;
     cout<<"sifre girniz:"<<endl;
     cin>>sifre;
     for(j=0;j<8;j++)
     for(i=0;i<26;i++)
     {
                      if (sifre[j]==harf[i].deger)//harfi kaydetme
                      sfr[j]=harf[i].s_deger; // sayıları kaydetme
                      }
                      j=0;
                      
                      dosyaAdi="sifreli.txt";
                      ifstream dosya1;
                      dosya1.open(dosyaAdi);
                      while(e=dosya.peek()!=EOF)
                      {
                           dosya.get(e);
                           for(i=0;i<26;i++)
                           if(e==harf[i].deger)
                           {
                                               s=(harf[i].s_deger+sfr[j])%26;
                                               for(k=0;k<26;k++)
                                               {
                                                                if(s==harf[k].s_deger)
                                                                x=harf[k].deger;
                                                                }
                                                                dosya1.put(x);
                                                                if(j<7) j++;
                                                                else 
                                                                j=0;
                                                                }
                                                                }
                                                                cout<<"dosya basarili bir sekilde sifrelendi"<<endl;
                                                                dosya.close();
                                                                dosya1.close();
                                                                }
                                                      
Last edited on
ifstream dosya1; Input stream
dosya1.put(x); output operation

You are trying to do output with an input stream.

By the way, the indentation makes the code really hard to read.
Take a look at this article:
http://en.wikipedia.org/wiki/Indent_style
Chervil, thanks for helping and suggestion.I got it.
Topic archived. No new replies allowed.