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
|
//
// main.cpp
// CopyArray
//
// Created by Alek Gulbenkian on 9/22/16.
// Copyright © 2016 Alek Gulbenkian. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, const char * argv[])
{
char *p, *b, test[] = "The thousand injuries of Fortunato I had borne as I best could, but when he ventured upon insult I vowed revenge. You, who so well know the nature of my soul, will not suppose, however, that gave utterance to a threat. At length I would be avenged; this was a point definitely, settled but the very definitiveness with which it was resolved precluded the idea of risk. I must not only punish but punish with impunity. A wrong is unredressed when retribution overtakes its redresser. It is equally unredressed when the avenger fails to make himself felt as such to him who has done the wrong." ;
// cout<< "Enter the amount of char per length you would want: ";
//int length = 60;
// cin>>length;
p = b =test;
if(p) do
{
while(*p == ' ' && *(p+1) == ' ')
p++;
}
while((*b++ = *p++));
int counter =0;
char *z = test;
for(int i =0; z[i]; i++)
{
if(counter ==0 && isspace(z[i]))
z[i] = z[i+1];
else
{
counter ++;
if(counter == 60 && !isspace(z[i-1]))
{
cout<<"-";
cout<<"\n";
counter =0;
}
else if(counter ==60 && isspace(z[i]))
{
cout<<"\n";
counter =0;
}
else if(counter ==60)
{
cout<< "\n";
counter =0;
}
}
cout<<z[i];
}
cout<<endl;
// cout<<test<<endl;;
}
code runs:
The thousand injuries of Fortunato I had borne as I best co-
uld, but when he ventured upon insult I vowed revenge. You,
who so well know the nature of my soul, will not suppose, ho-
wever, that gave utterance to a threat. At length I would be-
avenged; this was a point definitely, settled but the very
definitiveness with which it was resolved precluded the idea-
of risk. I must not only punish but punish with impunity. A-
wrong is unredressed when retribution overtakes its redress-
er. It is equally unredressed when the avenger fails to make-
himself felt as such to him who has done the wrong.
|