Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gürcan Güleç
/
iag0581
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
360ff60d
authored
Dec 01, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified number.c file
parent
fc6f6d73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
labs/lab10/number.c
labs/lab10/number.c
View file @
360ff60d
/**
* File: number.c
* Author: Gurcan Gulec
* Created: 30 November 2016
* Last edit: 01 December 2016
*
* Description: Homework about files for lab 10.
*
*/
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
// for atoi function
int
main
()
int
main
()
{
{
// creating the file pointers we are going to need
FILE
*
fp
=
fopen
(
"bad_input.txt"
,
"r"
);
FILE
*
fp
=
fopen
(
"bad_input.txt"
,
"r"
);
FILE
*
ep
=
fopen
(
"even.txt"
,
"w"
);
FILE
*
ep
=
fopen
(
"even.txt"
,
"w"
);
FILE
*
op
=
fopen
(
"odd.txt"
,
"w"
);
FILE
*
op
=
fopen
(
"odd.txt"
,
"w"
);
// char string we are going to use with fgets function
char
number
[
10
];
char
number
[
10
];
// checking if the files was opened
if
(
fp
==
NULL
||
ep
==
NULL
||
op
==
NULL
)
if
(
fp
==
NULL
||
ep
==
NULL
||
op
==
NULL
)
{
{
...
@@ -16,6 +32,8 @@ int main()
...
@@ -16,6 +32,8 @@ int main()
else
else
{
{
printf
(
"File was opened.
\n
"
);
printf
(
"File was opened.
\n
"
);
// creating a loop to check the lines
while
(
fgets
(
number
,
10
,
fp
)
!=
NULL
)
while
(
fgets
(
number
,
10
,
fp
)
!=
NULL
)
{
{
...
@@ -28,6 +46,8 @@ int main()
...
@@ -28,6 +46,8 @@ int main()
break
;
break
;
}
}
}
}
// making sure the values are numbers only
for
(
int
i
=
size
-
1
;
i
>=
0
;
i
--
)
for
(
int
i
=
size
-
1
;
i
>=
0
;
i
--
)
{
{
...
@@ -42,8 +62,13 @@ int main()
...
@@ -42,8 +62,13 @@ int main()
int
myNumber
;
int
myNumber
;
if
(
size
>
0
)
if
(
size
>
0
)
{
{
// convertin string into an integer
myNumber
=
atoi
(
number
);
myNumber
=
atoi
(
number
);
// finding out which ones are odd and which ones are even
// and writing them to files
if
(
myNumber
%
2
)
if
(
myNumber
%
2
)
{
{
fprintf
(
op
,
"%d
\n
"
,
myNumber
);
fprintf
(
op
,
"%d
\n
"
,
myNumber
);
...
@@ -55,7 +80,9 @@ int main()
...
@@ -55,7 +80,9 @@ int main()
}
}
}
}
fclose
(
fp
);
// closing the files
fclose
(
fp
);
fclose
(
ep
);
fclose
(
ep
);
fclose
(
op
);
fclose
(
op
);
}
}
...
...
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