Okay nu virker programmet som det skal:
#include <stdio.h>
#include <string.h>
char xText[] = "Tid(sek)";
char yText[] = "Temp(C)";
char a[16][45] =
{
{" "},
{" "},
{" ^ "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" | "},
{" +---|---|---|---|---|-> "},
{" "},
{" "}
};
void Putstr(int x, int y, const char* s)
{
int i;
for(i = 0; s[i]; i++)
a[y][x + i] = s[i];
}
void Putstr1(int x, int y, const char* s)
{
int i;
for(i = 0; s[i]; i++)
a[x][y + i] = s[i];
}
int main()
{
int l, i;
double minx;
double maxx;
double miny;
double maxy;
int n;
Putstr(15, 12, "*");
Putstr(16, 12, "*");
Putstr(17, 11, "*");
Putstr(18, 10, "*");
Putstr(20, 9, "*");
Putstr(21, 8, "*");
Putstr(23, 7, "*");
Putstr(24, 5, "*");
Putstr(25, 6, "*");
Putstr(26, 5, "*");
Putstr(27, 4, "*");
Putstr(28, 4, "*");
Putstr(29, 5, "*");
Putstr(30, 6, "*");
Putstr(31, 6, "*");
Putstr(32, 6, "*");
Putstr(33, 5, "*");
Putstr(34, 5, "*");
printf("Minimums og maksimums værdi på x-aksen: ");
fflush(stdout);
scanf("%lf, %lf", &minx, &maxx);
printf("Minimums og maksimums værdi på y-aksen: ");
fflush(stdout);
scanf("%lf, %lf", &miny, &maxy);
// x-aske intervalværdier:
for(n = 0; n < 1; n++)
{
char s[32];
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(13, 14, s);
}
for(n = 1; n < 2; n++)
{
char t[32];
sprintf(t, "%.1f", ((maxx-minx)/5)*n);
Putstr(17, 15, t);
}
for(n = 2; n < 3; n++)
{
char u[32];
sprintf(u, "%.1f", ((maxx-minx)/5)*n);
Putstr(21, 14, u);
}
for(n = 3; n < 4; n++)
{
char v[32];
sprintf(v, "%.1f", ((maxx-minx)/5)*n);
Putstr(24, 15, v);
}
for(n = 4; n < 5; n++)
{
char b[32];
sprintf(b, "%.1f", ((maxx-minx)/5)*n);
Putstr(29, 14, b);
}
for(n = 5; n < 6; n++)
{
char d[32];
sprintf(d, "%.1f", ((maxx-minx)/5)*n);
Putstr(32, 15, d);
}
// y-aske intervalværdier:
for(n = 0; n < 1; n++)
{
char e[32];
sprintf(e, "%.f", ((maxy-miny)/5)*n);
Putstr(11, 13, e);
}
for(n = 1; n < 2; n++)
{
char r[32];
sprintf(r, "%.1f", ((maxy-miny)/5)*n);
Putstr(8, 11, r);
}
for(n = 2; n < 3; n++)
{
char g[32];
sprintf(g, "%.1f", ((maxy-miny)/5)*n);
Putstr(8, 9, g);
}
for(n = 3; n < 4; n++)
{
char f[32];
sprintf(f, "%.1f", ((maxy-miny)/5)*n);
Putstr(8, 7, f);
}
for(n = 4; n < 5; n++)
{
char h[32];
sprintf(h, "%.1f", ((maxy-miny)/5)*n);
Putstr(8, 5, h);
}
for(n = 5; n < 6; n++)
{
char m[32];
sprintf(m, "%.1f", ((maxy-miny)/5)*n);
Putstr(7, 3, m);
}
memcpy(a[1] + 10, yText, strlen(yText));
memcpy(a[13] + 45 - strlen(xText), xText, strlen(xText));
for(l = 0; l < 16; l++,printf("\n"))for(i=0; i<45; i++)
{
printf("%c", a[l][i]);
}
return 0;
}
Men det jeg vil høre er om du har en ide på hvordan jeg kan lave Løkkerne om så de fylder mindre. Jeg tænkte måske at gøre det på følgende måde:
for(n = 0; n < 6; n++)
{
char s[32];
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(13, 14, s);
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(17, 15, s);
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(21, 14, s);
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(24, 15, s);
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(29, 14, s);
sprintf(s, "%.1f", ((maxx-minx)/5)*n);
Putstr(32, 15, s);
}