Commit 72baf597 authored by Alan Marchiori's avatar Alan Marchiori
Browse files

before lec 5

parent e63dac72
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[80] = "csci206";
int i = 42;
int *pi = &i;
printf("step1\n");
strcat(str, " is cool");
printf("step2"); fflush(stdout);
pi[5] = 0;
printf("\n%s (%d)\n", str, i);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE *file;
if (argc <= 1){
printf("please speficy filename on the command line.\n");
exit(1);
} else {
printf ("writing to %s\n", argv[1]);
}
file = fopen(argv[1], "w");
fprintf(file, "Hello file world!\n");
fclose(file);
}
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc <= 1){
printf("Please supply a filename on the command line.\n");
exit(1);
} else {
printf("writing to %s\n", argv[1]);
}
char *message = "Hello file world!\n";
int file_handle = open(argv[1],
O_WRONLY | O_CREAT,
S_IRWXU | S_IRWXG | S_IROTH);
write (file_handle, message, strlen(message));
close (file_handle);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment