Hey guys, new to the forum here.
EDIT: Alright guys, sorry about this whole edit, i'm doing more research and tests on this. The code basically is designed to center my text. Now I want to be able to insert double variables into this equation. I've tested the sprintf function outside of my program using %.0f and this works good, i can print the double variables. Now when I use it in my program I get a "buffer = 0, its too small error". How can i get around this?
Code:
void center (char* w)
{
int l, c;
char length [80]; //sets a character array to 80
l = sprintf_s(length,"%s", w); //calculates length of string
l = ((80-l)/2); //calculates amount of spaces on the left side
printf("\n");
for (c = 0; c < l; c++) //inserts spaces before the string
printf(" ");
printf("%s",w); //inserts the string, then creates a new line
}
int main ()
{
double a, b, c;
char text [80];
sprintf_s(text,"Equation #%d\n\n",count);
center(text);
center("Enter coefficient of x^2: ");
scanf_s("%d", &a);
center("Enter coefficient of x^1: ");
scanf_s("%d", &b);
center("Enter coefficient of x^0: ");
scanf_s("%d", &c);
sprintf_s(text,"Equation #%d\n\n",count);
center(text);
sprintf_s(text, "Is F ( x ) = %d x ^ 2 + %d x ^ 1 + %d x ^ 0 the correct equation? Y/N? ", a, b, c);
center(text);
cin >> reply;
cin.get ();
return (0)
}
Thanks guys! I'm new to C++, just started 2 weeks ago