-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasst4.cpp
More file actions
96 lines (75 loc) · 1.52 KB
/
asst4.cpp
File metadata and controls
96 lines (75 loc) · 1.52 KB
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
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <cstdlib>
#include <string.h>
#include <math.h>
#include <vector>
using namespace std ;
int main(int argc, char* argv[])
{
int messageLength;
int loopCounter= 0;
bool isPerfect = false;
int i = 0;
char c[8192];
FILE *fp = fopen(argv[1],"r");
if (fp == NULL)
{
cout << "empty file \n";
return 0;
}
while(!feof(fp))
{
char z = fgetc(fp);
if (!isspace(z))
{
loopCounter++;
c[i] = z;
++i;
}
}
loopCounter--;
for (int j = 0; j < loopCounter; ++j)
{
if (loopCounter == j*j)
{
isPerfect = true;
}
}
while (!isPerfect)
{
++loopCounter;
for (int j = 0; j < loopCounter; ++j)
{
if (loopCounter == j*j)
{
isPerfect = true;
}
}
}
double squareSize = (double) loopCounter;
int anotherInt = loopCounter;
int squareLength = (int) sqrt(loopCounter);
char dArray[squareLength][squareLength];
cout << "Contents of message before scramble: " << endl;
for (int j = 0; j < squareLength; ++j)
{
for (int k = 0; k < squareLength; ++k)
{
dArray[j][k] = c[loopCounter-anotherInt];
--anotherInt;
cout << dArray[j][k];
}
}
cout << endl << "Contents of message after scramble: " << endl;
for (int k = 0; k < squareLength; ++k)
{
for (int j = 0; j < squareLength; ++j)
{
cout << dArray[j][k];
}
}
cout << endl;
return 0;
}