Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sprintf_s was not declared in this scope

Tags:

c

linux

tr24731

I have a C program that uses sprintf_s. It works fine in Windows, but when I compile my code in Linux it gives this error:

sprintf_s was not declared in this scope. 

Why does this happen and how can I fix it?

like image 814
SPB Avatar asked Jan 28 '11 12:01

SPB


People also ask

Where is Sprintf_s defined?

The sprintf_s is defined in the stdio. h header file and is the security-enhanced alternate of the sprintf function. It uses a format string and corresponding arguments to generate a string that stores in the provided destination string.

What is the meaning of printf was not declared in this scope?

Printf() is defined in the stdio. h and implemented in the libc library. Older versions of C did not require a declaration before calling a function.

What is the difference between Sprintf and Sprintf_s?

One main difference between sprintf_s and sprintf is that sprintf_s checks the format string for valid formatting characters, whereas sprintf only checks if the format string or buffer are NULL pointers.


2 Answers

It's not standard, you won't find such function on Linux.

Standard function snprintf should have a similar semantics.

like image 89
peoro Avatar answered Sep 18 '22 15:09

peoro


sprintf_s is not part of the standard C library, so it is not portable, thus you are not able to use it in Linux. BUT you have snprintf, which is very similar and it should help you to accomplish what you want.

like image 32
gnclmorais Avatar answered Sep 20 '22 15:09

gnclmorais