I really like the following way of doing it, and it seems to work on new compiler,
But my c compiler doesn't seem to support snprintf. What alternative do i have?
Thanks!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void getNetworkAtPriority(char* buffer, size_t bufferLength)
{
snprintf(buffer, bufferLength, "mcc-mnc-umts");
}
int main()
{
char entry1[14];
getNetworkAtPriority(entry1, 14);
printf("Return:%s", entry1);
return 0;
}
Just use memcpy.
You should try to avoid the printf functions if you don't need the advanced formatting they provide.
True story, I once worked a at a bank, contracted to re-architect the code for the teller systems for an eventual port to Java ( which coincidentally never happened... Over a decade later, that same C++ code is running strong... ). Anyway in the process of modularizing a ton of code I happened to get into a low level logging function. Basically every single transaction was logged to the file system, so if there was fraud, a crash, whatever, they could play back each individual tellers transactions at the application level. Anyways there was a call to fprintf that always copied the same sized buffer ( a time stamp ) to a fixed sized string, I swapped out to use a straight memory copy instead...
Net effect? The entire application nearly doubled in speed. We were actually getting thank you emails from the branches over making such big improvements to the application,
Sorry, old many memory moment is now complete.