Last active
October 26, 2016 22:20
-
-
Save jonepl/2c795f1c99fd632fdb65f5909836ddd3 to your computer and use it in GitHub Desktop.
Easy concatenation and writing to a file in C
This file contains 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 <lib.h> // provides _syscall and message | |
#include <unistd.h> // provides function prototype | |
#include <stdio.h> // printf | |
int main() { | |
int processID = 10; | |
long timestamp = 123456789; | |
char fromState[20] = "RDY"; | |
char toState[20] = "RUN"; | |
char buffer[100]; | |
FILE *fp = fopen("proc-states", "w+"); | |
if (fp == NULL) { printf("Error opening file!\n"); return 0; } | |
char buffer[100]; | |
sprintf(buffer, "%d\t%ld\t%s\t%s\n", processID, timestamp, fromState, toState); | |
fprintf(fp, "%s\n", buffer); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment