codice:
#include <stdio.h>
#include <strings.h>
#include <malloc.h>
class Stringa
{
private:
char *s;
int lunghezza;
int max;
public:
Stringa(void)
{
s = (char *)malloc(513);
s[0] = '\0';
lunghezza = 0;
max = 512;
}
Stringa(char *p)
{
s = (char *)malloc(513);
int i;
for (i = 0; (s[i] = p[i]) != '\0'; i++)
;
lunghezza = i;
max = 512;
}
Stringa(int k)
{
s = (char *)malloc(k+1);
s[0] = '\0';
lunghezza = 0;
max = k;
}
Stringa(char *p, int k)
{
s = (char *)malloc(k);
int i;
for (i = 0; (s[i] = p[i]) != '\0'; i++)
;
lunghezza = i;
max = k;
}
Stringa(const Stringa& x)
{
max = (x.lunghezza)+1;
s = (char *)malloc(max);
for (lunghezza = 0; lunghezza < x.lunghezza; lunghezza++)
s[lunghezza] = x.s[lunghezza];
}
~Stringa(void)
{
s[0] = '\0';
lunghezza = 0;
max = 0;
}
void write(void)
{
printf("%s",s);
}
void writeln(void)
{
printf("%s\n",s);
}
int lung(void)
{
return lunghezza;
}
void input(void)
{
char c;
int i;
for (i = 0; (c = getchar()) != '\n' && i < max; i++)
s[i] = c;
s[i] = '\0';
lunghezza = i;
fflush(stdin);
}
void modifica(int i, char c)
{
if (i > 0 && i <= lunghezza)
s[i-1] = c;
}
Stringa operator=(const Stringa& x)
{
strcpy(s,x.s);
lunghezza = x.lunghezza;
}
int operator==(Stringa &x)
{
return !(strcmp(s,x.s));
}
int operator==(char *x)
{
return !(strcmp(s,x));
}
int operator<(Stringa &x)
{
return (strcmp(s,x.s) == -1);
}
int operator<(char *x)
{
return (strcmp(s,x) == -1);
}
int operator>(Stringa &x)
{
return (strcmp(s,x.s) == 1);
}
int operator>(char *x)
{
return (strcmp(s,x) == 1);
}
int operator<=(Stringa &x)
{
return ((*this == x) || (*this < x));
}
int operator<=(char *x)
{
return ((*this == x) || (*this < x));
}
int operator>=(Stringa &x)
{
return ((*this > x) || (*this == x));
}
int operator>=(char *x)
{
return ((*this > x) || (*this == x));
}
Stringa operator+(Stringa &x)
{
Stringa z;
int i,k;
for (i = 0; s[i] != '\0'; i++)
z.s[i] = s[i];
for (k = 0; x.s[k] != '\0'; k++)
z.s[i++] = x.s[k];
z.s[i] = '\0';
z.lunghezza = i;
return z;
}
void operator+=(Stringa &x)
{
*this = (*this + x);
}
void operator=(char *z)
{
int i;
for (i = 0; (s[i] = z[i]) != '\0'; i++)
;
lunghezza = i;
}
};
eccola...
nel costruttore di copia non allocavo e poi non c'era l'operatore= (Stringa)