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
fc6f6d73
authored
Dec 01, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
committing number.c to the right directory
parent
2dc06202
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
labs/lab10/number.c
labs/lab10/number.c
0 → 100644
View file @
fc6f6d73
#include <stdio.h>
#include <stdlib.h>
int
main
()
{
FILE
*
fp
=
fopen
(
"bad_input.txt"
,
"r"
);
FILE
*
ep
=
fopen
(
"even.txt"
,
"w"
);
FILE
*
op
=
fopen
(
"odd.txt"
,
"w"
);
char
number
[
10
];
if
(
fp
==
NULL
||
ep
==
NULL
||
op
==
NULL
)
{
printf
(
"File was not opened.
\n
"
);
}
else
{
printf
(
"File was opened.
\n
"
);
while
(
fgets
(
number
,
10
,
fp
)
!=
NULL
)
{
int
size
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
if
(
number
[
i
]
==
'\0'
)
{
size
=
i
;
break
;
}
}
for
(
int
i
=
size
-
1
;
i
>=
0
;
i
--
)
{
if
(
number
[
i
]
<
48
||
number
[
i
]
>
57
)
{
number
[
i
]
=
'\0'
;
size
=
i
;
}
}
int
myNumber
;
if
(
size
>
0
)
{
myNumber
=
atoi
(
number
);
if
(
myNumber
%
2
)
{
fprintf
(
op
,
"%d
\n
"
,
myNumber
);
}
else
{
fprintf
(
ep
,
"%d
\n
"
,
myNumber
);
}
}
}
fclose
(
fp
);
fclose
(
ep
);
fclose
(
op
);
}
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