(Need Help) make faild compile vigenere cipher

hay guys, i have a problem when i compile my workspace
this my code
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
if (argc < 5) {
cout << "VF [E|D] [IN] [OUT] [KEY]";
exit(1);
}
else {
ifstream Fin (argv[2]);
ofstream Fout(argv[3]);
string key = argv[4];
int len = key.length();
if (len < 3) {
cout << "Key at least 3 chars" << endl;
exit(1);
}
char cc;
/* Calculate m */
int m = 0;
for (int j=0; j<len; j++) {
cc = key[j];
if (cc >= 97 && cc <= 122 ) {
cc -= 32;
}
m += (int) cc;
}
m = 1 + (m % (len-1));
int i = 0;
cc = Fin.get();
while (cc != EOF) {
if (cc >= 97 && cc <= 122 ) {
cc -= 32;
}
if (cc >= 65 && cc <= 90) {
int delta = key[0];
if (argv[1][0] == 'E') {
cc = ((cc + delta) % 26) + 65;
}
else { // 'D'
cc = ((cc - delta + 26) % 26) + 65;
}
/* Generate key */
char ccc = ((key[0]+key[m])%26)+65;
for (int j=0; j<len-1; j++) {
key[j] = key[j+1];
}
key[len-1] = ccc;
i++;
}
Fout << cc;
cc = Fin.get();
}
Fin.close();
Fout.close();
}
return 0;
}
Last edited on
would you please provide the compile error message?
this error message,..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Info :Compiling C:\BC5\BIN\noname00.cpp
Error:  noname00.cpp(1,2):Unable to open include file 'CSTDLIB.H'
Warn :  string.h(549,3):Functions containing for are not expanded inline
Warn :  string.h(557,3):Functions containing while are not expanded inline
Warn :  string.h(563,3):Functions containing for are not expanded inline
Warn :  string.h(575,3):Functions containing for are not expanded inline
Warn :  string.cc(686,32):Comparing signed and unsigned values
Warn :  noname00.cpp(27,6):Conversion may lose significant digits
Warn :  noname00.cpp(33,5):Conversion may lose significant digits
Warn :  noname00.cpp(36,6):Conversion may lose significant digits
Warn :  noname00.cpp(41,5):Conversion may lose significant digits
Warn :  noname00.cpp(44,5):Conversion may lose significant digits
Warn :  noname00.cpp(47,33):Conversion may lose significant digits
Warn :  noname00.cpp(55,5):Conversion may lose significant digits
although it looks horrible i can confirm i get no errors or warnings on Vs2010, win8.
iwank7, try changing #include <cstdlib> to #include <stdlib.h> .
i use borland c++ 5.02 and win7,...
ok i will try to use vs2010,...
thank's for your attention
Grey Wolf : thank's for reply, but i still got warn message
how to fix that???
If I'm correct, that compiler is so old, it probably pre-dates the old C++ standard. it's not surprising it's throwing a wobbly.

That code should compile without warnings, when using a conforming compiler.

In the meantime, maybe you shouldn't use stdlib.h at all, and use "return" rather than "exit()".

When you include <stdlib.h> instead of <cstdlib>, you're mixing in a version that is incompatible with the C++ standard library.

It appears the only reason you have stdlib.h included is exit(). If you don't have a specific reason for using exit(), I suggest using return instead, and not including stdlib.h

Borland C++ 5.02 - (1997)
it's a very old compiler, which is older than c++ 03, which means, you may not be able to use cstdlib. so do not try to use this compiler.
Topic archived. No new replies allowed.