Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic patterns(words). What it does is takes a string as a parameter, determines length of string, tests if the length is a perfect square, if it is then it makes a 2-d array with its length and height equal to the lengths root. If it isn't then it cuts it down to size that is a perfect square. Then it does some other stuff that is irrelevant for my problem. If anyone wants a complete explanation of the source just let me know. When i try to compile these error statements come up.
1) at line 41- expected unqualified-id before "if"
2)at line 41- expected `,' or `;' before "if"
3)at line 44- expected unqualified-id before '||' token
4)at line 44- expected `,' or `;' before '||' token
5)at line 50- expected unqualified-id before "return"
6)at line 50- expected `,' or `;' before "return"
7)at line 51- expected declaration before '}' token
here is the source, please help. - #include <string>
-
#include <cstdlib>
-
using namespace std;
-
-
string tranString( string letters){
-
int length = letters.length();
-
int arrayLength;
-
int arrayHeight;
-
int extraLength = 0;
-
int column;
-
int subStr;
-
int row;
-
string beforeMix [arrayLength][arrayHeight];
-
-
for ( int n = 1; n < length; n++){
-
if( length % n == 0 && length / n == n){
-
arrayLength = length / n;
-
arrayHeight = arrayLength;
-
bool perSquare = 0;
-
n = length;
-
}
-
else if( (length - n) % n == 0 && (length - n) / n == n ){
-
arrayLength = length - n;
-
arrayHeight = length - n;
-
extraLength = n;
-
}
-
-
}
-
-
for (row = 0 ; row <= arrayHeight - 1; row++){
-
for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
-
beforeMix[column][row] = letters.substr(subStr, 1);
-
}
-
}
-
string newOrder = "";
-
for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
-
for( row = arrayHeight - 1; row > -1; row--){
-
newOrder.substr( subStr, 1) = beforeMix[column][row];
-
}
-
}
-
if( newOrder.length() % 2 == 0;){
-
newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
else
-
{
-
newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
-
-
return letters;
-
}
-
-
9 27586
Can you tell us what do you think that this does: - newOrder.substr( subStr, 1) = beforeMix[column][row];
?
Also you don't need this ';' here: - if( newOrder.length() % 2 == 0;)
:D
,regards
Savage
Ok so I sort of found the problem, I was forgetting a "{" at line 36. The line is very long so i didn't see it. To savage, the code sets the designated sub string equal to the string, really just one letter. Now the code compiles, but it hangs. Again help would be appreciated :). This is the new code - #include <string>
-
#include <cstdlib>
-
using namespace std;
-
-
string tranString( string letters){
-
int length = letters.length();
-
int arrayLength;
-
int arrayHeight;
-
int extraLength = 0;
-
int column;
-
int subStr;
-
int row;
-
string beforeMix [arrayLength][arrayHeight];
-
for ( int n = 1; n < length; n++){
-
if( length % n == 0 && length / n == n){
-
arrayLength = length / n;
-
arrayHeight = arrayLength;
-
bool perSquare = 0;
-
n = length;
-
}
-
else if( (length - n) % n == 0 && (length - n) / n == n ){
-
arrayLength = length - n;
-
arrayHeight = length - n;
-
extraLength = n;
-
}
-
-
}
-
-
-
for (row = 0 ; row <= arrayHeight - 1; row++){
-
for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
-
beforeMix[column][row] = letters.substr(subStr, 1);
-
}
-
}
-
string newOrder;
-
for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++){
-
for( row = arrayHeight - 1; row > -1; row--){
-
newOrder.substr( subStr, 1) = beforeMix[column][row];
-
}
-
}
-
if( newOrder.length() % 2 == 0){
-
newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
else
-
{
-
newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
-
-
return newOrder;
-
}
- for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
-
{
-
for( row = arrayHeight - 1; row > -1; row--)
-
{
-
newOrder.substr( subStr, 1) = beforeMix[column][row];
-
}
-
}
-
Why are the conditions in for loop for column and row >-1?
And this: - newOrder.substr( subStr, 1) = beforeMix[column][row];
doesn't do what you think it does.This creates a new string of 1 letter length,and then it assigns to that string beforeMix[column][row].If you wish to change a single letter in the string you can use the std::string's overloaded operator[],just like you would change an element of an array.If you wish to replace more then one letter you can use std::string::replace
,regards
Savage
K so I should have seen the -1. I was using that before I remembered =>. So I will change that. And thanks for the string thing, I would have never caught that. Hopefully it will work now. Vielen Dank!!!
Ok so I think I'm getting somewhere, but no it isn't hanging it just isn't compiling.
Here are the error messages.
1)38 no matching function for call to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::replace(int&, <unknown type>, std::string&)'
2)39 request for member `length' in `beforeMix', which is of non-class type `std::string[((unsigned int)((int)arrayLength))][((unsigned int)((int)arrayHeight))]'
Again Help would be much appreciated. - #include <string>
-
#include <cstdlib>
-
using namespace std;
-
-
string tranString( string letters){
-
int length = letters.length();
-
int arrayLength;
-
int arrayHeight;
-
int extraLength = 0;
-
int column;
-
int subStr;
-
int row;
-
string beforeMix [arrayLength][arrayHeight];
-
-
for ( int n = 1; n < length; n++){
-
if( length % n == 0 && length / n == n){
-
arrayLength = length / n;
-
arrayHeight = arrayLength;
-
bool perSquare = 0;
-
n = length;
-
}
-
else if( (length - n) % n == 0 && (length - n) / n == n ){
-
arrayLength = length - n;
-
arrayHeight = length - n;
-
extraLength = n;
-
}
-
-
}
-
-
for (row = 0 ; row <= arrayHeight - 1; row++){
-
for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
-
beforeMix[column][row] = letters.substr(subStr, 1);
-
}
-
}
-
string newOrder;
-
for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
-
for( row = arrayHeight - 1; row >= 0; row--){
-
newOrder.replace(subStr, beforeMix[column][row].length, beforeMix[column][row]);
-
subStr = (beforeMix.length[column][row].length) - 1;
-
}
-
}
-
if( newOrder.length() % 2 == 0){
-
newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
else
-
{
-
newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
-
}
-
-
-
return newOrder;
-
}
-
-
Ow boy... I feel retarded... Thanks a million though!
K, the program is back to hanging. Here is the source. - #include <string>
-
#include <cstdlib>
-
using namespace std;
-
string tranString( string letters){
-
getline (cin, letters);
-
int Length = letters.length();
-
int arrayLength;
-
int arrayHeight;
-
int extraLength = 0;
-
int column;
-
int subStr;
-
int row;
-
string beforeMix [arrayLength][arrayHeight];
-
-
for ( int n = 1; n < Length; n++){
-
if( Length % n == 0 && Length / n == n){
-
arrayLength = Length / n;
-
arrayHeight = arrayLength;
-
bool perSquare = 0;
-
n = Length;
-
}
-
else if( (Length - n) % n == 0 && (Length - n) / n == n ){
-
arrayLength = Length - n;
-
arrayHeight = Length - n;
-
extraLength = n;
-
}
-
-
}
-
-
for (row = 0 ; row <= arrayHeight - 1; row++){
-
for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= Length - extraLength - 1; column++, subStr++){
-
beforeMix[column][row] = letters.substr(subStr, 1);
-
}
-
}
-
string newOrder;
-
for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
-
for( row = arrayHeight - 1; row >= 0; row--){
-
newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
-
subStr = (beforeMix[column][row].length()) - 1;
-
}
-
}
-
if( newOrder.length() % 2 == 0){
-
newOrder.insert( (newOrder.length() / 2), letters.substr( (Length - extraLength) - 1, extraLength));
-
}
-
else
-
{
-
newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (Length - extraLength) - 1, extraLength));
-
}
-
-
-
return newOrder;
-
}
one last revision before I go to sleep - #include <string>
-
#include <cstdlib>
-
using namespace std;
-
-
string tranString( string letters){
-
//determines length of letters
-
int stringLength = letters.size();
-
//preps before mix dimensions
-
int arraySize = 1;
-
int arrayHeight = 1;
-
//sets extralength = 0
-
int extraLength = 0;
-
//initalizes positions in array and string
-
int column = 0;
-
int row = 0;
-
int subStr = 0;
-
//initalizes array for text, As of march 16 it goes this far
-
string beforeMix[arraySize][arrayHeight];
-
//determines if stringlength is a perfect square
-
for ( int n = 1; n <= stringLength; n++){
-
if( stringLength % n == 0 && (stringLength / n) == n){
-
arraySize = stringLength / n;
-
arrayHeight = arraySize;
-
n = stringLength;
-
}
-
else if( (stringLength - n) % n == 0 && (stringLength - n) / n == n ){
-
arraySize = stringLength - n;
-
arrayHeight = stringLength - n;
-
extraLength = n;
-
}
-
-
}
-
-
for (row = 0 ; row <= arrayHeight - 1; row++){
-
for ( column = 0, subStr = 0; column <= arraySize - 1, subStr <= stringLength - extraLength - 1; column++, subStr++){
-
beforeMix[column][row] = letters.substr(subStr, 1);
-
}
-
}
-
string newOrder;
-
for( column = arraySize - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
-
for( row = arrayHeight - 1; row >= 0; row--){
-
newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
-
subStr = (beforeMix[column][row].length()) - 1;
-
}
-
}
-
if( newOrder.length() % 2 == 0){
-
newOrder.insert( (newOrder.length() / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
-
}
-
else
-
{
-
newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
-
}
-
-
-
return newOrder;
-
}
-
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ng Pheng Siong |
last post by:
Hi,
I just noticed that demo/evp_ciph_test.py of my M2Crypto package
causes a core dump. It used to not do that. ;-)
The core dump happens when the program is exiting; in the output below,...
|
by: Steven T. Hatton |
last post by:
I just read this in the description of how C++ is supposed to be
implemented:
"All external object and function references are resolved. Library
components are linked to satisfy external...
|
by: Paul T. Rong |
last post by:
Sorry I just lost tracks of a series of posts, so I post my question again,
hoping someone can help.
Here is codes provided by Jeff Smith
> Private Sub Form_Load()
> Dim db As...
|
by: hsharsha |
last post by:
Consider the below code:
int main(void)
{
class inner
{};
friend class inner; /* what does this signify???? */
return 0;
}
|
by: utab |
last post by:
Dear all,
Is there a clear distinction how to decide which functions to be
members of a class and which not
How is your attitude (Your general way from your experiences ...)
"If the...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
Dim sCoName As String = oDs.Customers(0).CompanyName
The part that I want to understand is the oDs.Customers(0). Does
oDs.Customers(0) mean 1st row of the datatable Customers. Where can I find...
|
by: PengYu.UT |
last post by:
Hi,
I'm wondering what 'c' in "cout", "cin" mean? Does it mean "C++"? Or
the 'c' in <cassert>?
Thanks,
Peng
|
by: dolphin |
last post by:
Hi All
I read a .cpp files,find that
static void fun(void){......}
int main()
{
..........
}
What does this static function mean?Is it the same as the static
|
by: bobby |
last post by:
hello group,
what does for( ; ; ) mean in C program
Thanks
|
by: Blau |
last post by:
I am trying to follow some tutorials, and I came across this bit of
code:
public void AddBackground(string backgroundKey, string textureName,
Vector2 position, Rectangle? sourceRect, float...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |