Created
July 7, 2018 21:26
-
-
Save thebirk/6ff812dddacdedf10b0d025991c15d21 to your computer and use it in GitHub Desktop.
Simple build number counter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char **argv) { | |
if(argc != 2) { | |
printf("Usage: buildnum <file>\n"); | |
return 1; | |
} | |
FILE *f = fopen(argv[1], "rb"); | |
if(!f) { | |
f = fopen(argv[1], "wb"); | |
if(!f) { | |
printf("failed to open/create file\n"); | |
return 1; | |
} | |
} | |
int buildnumber = -1; | |
int filled = fscanf(f, "%d", &buildnumber); | |
if(filled != 1) { | |
buildnumber = 1; | |
} else { | |
buildnumber++; | |
} | |
f = freopen(argv[1], "wb", f); | |
fprintf(f, "%d", buildnumber); | |
fflush(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment