Skip to content

Instantly share code, notes, and snippets.

/sprintf_test.c

Created Jul 16, 2016
Embed
What would you like to do?
/**
* test.c
*
* Computer Science 50
* Problem Set 4
*
* Tests sprintf command for recover.c.
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// create counter for naming outfile
int n = 0;
printf("n is %i\n", n);
// open target files
char imagenr = 0;
sprintf(&imagenr,"%'.3i.jpg", n);
printf("replacing n in 00n.jpg gives %s\n", &imagenr);
n++;
printf("n + 1; n is now %i\n", n);
sprintf(&imagenr,"%'.3i.jpg", n);
printf("replacing n in 00n.jpg gives %s\n", &imagenr);
n++;
printf("n + 1; n is now %i\n", n);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment