diff --git a/clibrary.c b/clibrary.c index 70c2756..dc49da2 100644 --- a/clibrary.c +++ b/clibrary.c @@ -288,15 +288,11 @@ void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Valu void LibSPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { struct OutputStream StrStream; - struct Value *DerefVal; - int DerefOffset; - StrStream.i.Str.WritePos = VariableDereferencePointer(StrStream.i.Str.Parser, Param[0], &DerefVal, &DerefOffset, NULL, NULL); - - if (DerefVal->Typ->Base != TypeArray) - ProgramFail(Parser, "can only print to arrays of char"); - + StrStream.Putch = &SPutc; StrStream.i.Str.Parser = Parser; + StrStream.i.Str.WritePos = Param[0]->Val->NativePointer; + GenericPrintf(Parser, ReturnValue, Param+1, NumArgs-1, &StrStream); PrintCh(0, &StrStream); ReturnValue->Val->NativePointer = *Param; diff --git a/tests/37_sprintf.c b/tests/37_sprintf.c new file mode 100644 index 0000000..c9ba3a5 --- /dev/null +++ b/tests/37_sprintf.c @@ -0,0 +1,8 @@ +char Buf[100]; +int Count; + +for (Count = 1; Count <= 20; Count++) +{ + sprintf(Buf, "->%02d<-\n", Count); + printf("%s", Buf); +} diff --git a/tests/37_sprintf.expect b/tests/37_sprintf.expect new file mode 100644 index 0000000..a643da8 --- /dev/null +++ b/tests/37_sprintf.expect @@ -0,0 +1,20 @@ +->01<- +->02<- +->03<- +->04<- +->05<- +->06<- +->07<- +->08<- +->09<- +->10<- +->11<- +->12<- +->13<- +->14<- +->15<- +->16<- +->17<- +->18<- +->19<- +->20<- diff --git a/tests/Makefile b/tests/Makefile index 31f42c9..b61bdd2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -29,7 +29,8 @@ TESTS= 00_assignment.test \ 29_array_address.test \ 34_array_assignment.test \ 35_sizeof.test \ - 36_array_initialisers.test + 36_array_initialisers.test \ + 37_sprintf.test %.test: %.expect %.c @echo Test: $*...