Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Courses
csci206_lecture_examples
Commits
72baf597
Commit
72baf597
authored
Jan 24, 2014
by
Alan Marchiori
Browse files
before lec 5
parent
e63dac72
Changes
5
Hide whitespace changes
Inline
Side-by-side
section01/Lec05/C File IO.odp
0 → 100644
View file @
72baf597
File added
section01/Lec05/PH1_1 - 1_3.odp
0 → 100644
View file @
72baf597
File added
section01/Lec05/bug.c
0 → 100644
View file @
72baf597
#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
);
}
section01/Lec05/file_cstd.c
0 → 100644
View file @
72baf597
#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
);
}
section01/Lec05/file_syscall.c
0 → 100644
View file @
72baf597
#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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment