The function is to return 1 if the formatting is successful and 0 if any errors, such as string length greater than width, are found. I'm getting errors though? What's wrong? I don't think I'm calling it right either...
#include <stdio.h>
int main()
{
int dummy, value = 0;
formatString(value);
scanf_s("%d",&dummy);
return 0;
}
int formatString (char *in,
char *out,
int width)
{
//Local Declarations
int spaces;
char *start;
char *walker;
int value;
spaces = (width – 1) – strlen(in);
if (spaces < 0)
{
value = 0;
}
else
{
start = out + (spaces / 2);
for (walker = out; walker < start; walker++)
*walker = ' ';
strcpy (start, in);
for (walker = out + strlen(out);
walker < out + width – 2;
walker++)
*walker = ' ';
*walker = ‘\0’;
}
return value;
}
Aucun commentaire:
Enregistrer un commentaire