By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Expected unqualified-id before 'return'?

P: 2
I've been working on a decryption program for another encryption program I made. It isn't finished, and when I try to compile it to test it, it gives me the error "expected unqualified-id before 'return'" right at the line where "return 0;" is. I am using Xcode for mac os, which is the same as g++ 4.0 for Unix/Linux. I can't seem to figure this out, and I can't test anything until it's fixed.

Any ideas?

Here's the code:
-----------------------
#include <iostream>
#include <fstream>
#include <cstdio>
#include <bitset>
using namespace std;

int main () {

char password[32];
char file[100];
char filedata[8448];
bool filebin[8448];
bool key[32][8];
bool splitholder[1056][8];
int length;
int totiterations;
int iteration = 1;
bool passwordbin[32][8];
bool holder[32][1024][8];

//Get information from user
cout << "Type in the name and location of the .spir file you wish to decode.\n";
cin >> file;
fstream inputfile;
inputfile.open(file, ios::in | ios::binary);
while(inputfile >> filedata)
// cout << filedata;
inputfile.close();
//cout << "\n\n";
int a = 0; /*Convert data from file into binary*/
while(a<8448){
if(!filedata[a]){
break;
}
if(filedata[a]=='0'){
filebin[a]=false;
}
else
{
filebin[a]=true;
}
// cout << filebin[a];
a++;
}
cout << "\n\n";
cout << "\n\nType in the password for the file.";
cin >> password;
length = strlen(password);

//Split the file into bytes
int b = 0,c = 0;
while(b<1056){
if(!filedata[b*8]){
break;
}
c = 0;
while(c<8){
splitholder[b][c] = filebin[(b*8)+c];
// cout << splitholder[b][c];
c++;
}
b++;
// cout << "\n";
}

//Separate the key from the file

//cout << length << "\n\n";
b = 0;
while(b<length){
c = 0;
while(c<8){
key[b][c] = splitholder[b][c];
// cout << key[b][c];
c++;
}
b++;
cout << "\n";
}

//Shift the file to cover key
b = 0;
while(b<1024){
c = 0;
while(c<8){
splitholder[b][c] = splitholder[b+length][c+length];
// cout << key[b][c];
c++;
}
b++;
cout << "\n";
}

//Erase extra data

b = 1024;
while(b<1056){
c = 0;
while(c<8){
splitholder[b][c] = false;
c++;
}
b++;
cout << "\n";
}

//Convert the password into binary
int p = 0;
int e = 0;
while(e<length){
int f = 0;
while(e<8){
++ e;
if((password[p]&(1 << e) ? '1' : '0')=='1'){
passwordbin[p][e]=true;
}else{
passwordbin[p][e]=false;
}
f++;
cout << passwordbin[p][e];
}
p++;
}

//Decode the key
bool d,o;
b = 0;
while(b<length){
c = 0;
while(c<8){
d = key[b][c];
o = passwordbin[b][c];
key[b][c] = (d||o)&&!(d&&o);
c++;
}
b++;
}

//Decrypt the message
totiterations = length;
int f = 0,g = 0;
bool x,y,z;
while(iteration<totiterations){
f = 0;
while(f<1024)
g = 0;
while(g<8){
if(iteration = 0){
holder[iteration][f][g] = splitholder[f][g];
}
if(f=0){
y=holder[iteration][f][g];
x=key[iteration][g];
z=(x||y)&&!(x&&y);
holder[iteration+1][f][g] = x;
holder[iteration+1][f+1][g] = z;
}
else{
y=holder[iteration][f][g];
x=holder[iteration+1][f][g];
z=(x||y)&&!(x&&y);
holder[iteration+1][f+1][g] = z;
}
g++;
}
f++;
}
iteration++;
}

//end the program
return 0;
}
-----------------------
Jul 8 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
P.S. I know the code is messy and inefficient, but it worked up until now.
Jul 8 '07 #2

Meetee
Expert Mod 100+
P: 931
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdio>
  4. #include <bitset>
  5. using namespace std;
  6.  
  7. int main () {
  8.  
  9. char password[32];
  10. char file[100];
  11. char filedata[8448];
  12. bool filebin[8448];
  13. bool key[32][8];
  14. bool splitholder[1056][8];
  15. int length;
  16. int totiterations;
  17. int iteration = 1;
  18. bool passwordbin[32][8];
  19. bool holder[32][1024][8];
  20.  
  21. //Get information from user
  22. cout << "Type in the name and location of the .spir file you wish to decode.\n";
  23. cin >> file;
  24. fstream inputfile;
  25. inputfile.open(file, ios::in | ios::binary);
  26. while(inputfile >> filedata)
  27. // cout << filedata;
  28. inputfile.close();
  29. //cout << "\n\n";
  30. int a = 0; /*Convert data from file into binary*/
  31. while(a<8448){
  32. if(!filedata[a]){
  33. break;
  34. }
  35. if(filedata[a]=='0'){
  36. filebin[a]=false;
  37. }
  38. else
  39. {
  40. filebin[a]=true;
  41. }
  42. // cout << filebin[a];
  43. a++;
  44. }
  45. cout << "\n\n";
  46. cout << "\n\nType in the password for the file.";
  47. cin >> password;
  48. length = strlen(password);
  49.  
  50. //Split the file into bytes
  51. int b = 0,c = 0;
  52. while(b<1056){
  53. if(!filedata[b*8]){
  54. break;
  55. }
  56. c = 0;
  57. while(c<8){
  58. splitholder[b][c] = filebin[(b*8)+c];
  59. // cout << splitholder[b][c];
  60. c++;
  61. }
  62. b++;
  63. // cout << "\n";
  64. }
  65.  
  66. //Separate the key from the file
  67.  
  68. //cout << length << "\n\n";
  69. b = 0;
  70. while(b<length){
  71. c = 0;
  72. while(c<8){
  73. key[b][c] = splitholder[b][c];
  74. // cout << key[b][c];
  75. c++;
  76. }
  77. b++;
  78. cout << "\n";
  79. }
  80.  
  81. //Shift the file to cover key
  82. b = 0;
  83. while(b<1024){
  84. c = 0;
  85. while(c<8){
  86. splitholder[b][c] = splitholder[b+length][c+length];
  87. // cout << key[b][c];
  88. c++;
  89. }
  90. b++;
  91. cout << "\n";
  92. }
  93.  
  94. //Erase extra data
  95.  
  96. b = 1024;
  97. while(b<1056){
  98. c = 0;
  99. while(c<8){
  100. splitholder[b][c] = false;
  101. c++;
  102. }
  103. b++;
  104. cout << "\n";
  105. }
  106.  
  107. //Convert the password into binary
  108. int p = 0;
  109. int e = 0;
  110. while(e<length){
  111. int f = 0;
  112. while(e<8){
  113. ++ e;
  114. if((password[p]&(1 << e) ? '1' : '0')=='1'){
  115. passwordbin[p][e]=true;
  116. }else{
  117. passwordbin[p][e]=false;
  118. }
  119. f++;
  120. cout << passwordbin[p][e];
  121. }
  122. p++;
  123. }
  124.  
  125. //Decode the key
  126. bool d,o;
  127. b = 0;
  128. while(b<length){
  129. c = 0;
  130. while(c<8){
  131. d = key[b][c];
  132. o = passwordbin[b][c];
  133. key[b][c] = (d||o)&&!(d&&o);
  134. c++;
  135. }
  136. b++;
  137. }
  138.  
  139. //Decrypt the message
  140. totiterations = length;
  141. int f = 0,g = 0;
  142. bool x,y,z;
  143. while(iteration<totiterations){
  144. f = 0;
  145. while(f<1024)
  146. g = 0;
  147. while(g<8){
  148. if(iteration = 0){
  149. holder[iteration][f][g] = splitholder[f][g];
  150. }
  151. if(f=0){
  152. y=holder[iteration][f][g];
  153. x=key[iteration][g];
  154. z=(x||y)&&!(x&&y);
  155. holder[iteration+1][f][g] = x;
  156. holder[iteration+1][f+1][g] = z;
  157. }
  158. else{
  159. y=holder[iteration][f][g];
  160. x=holder[iteration+1][f][g];
  161. z=(x||y)&&!(x&&y);
  162. holder[iteration+1][f+1][g] = z;
  163. }
  164. g++;
  165. }
  166. f++;
  167. }
  168. iteration++;
  169. } // Delete this
  170.  
  171. //end the program
  172. return 0;
  173. }
  174.  

One kind advice..!! Please write your code in CODE tags as given in instructions (right side when you write new thread) so it soesn't become messy :))

BTW the problem is one extra } that you have added before return 0. I think it is generating this error. Just remove it to get rid of the error!!!

Regards
Jul 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.