-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
51 lines (46 loc) · 1.04 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h> /*gives access to use ssize_t types*/
#include <string.h> /*gives access to use strtok*/
/**
* main - RSA Factoring Challenge.
* @argc: Arguement count.
* @argv: Arguement array.
* Return: 0 on EXIT_SUCCESS
*/
int main(int argc, char *argv[])
{
FILE *stream;
char *line = NULL;
char *end_ptr;
int base;
size_t len = 0;
ssize_t nread;
unsigned long long num;
unsigned long long test_num;
if (argc != 2)
{
fprintf(stderr, "USAGE: %s <file>\n", argv[0]);
exit(EXIT_FAILURE);
}
base = 10;
stream = fopen(argv[1], "r");
if (stream == NULL)
{
fprintf(stderr, "Error! Can't open file %s\n", argv[1]);
exit(EXIT_FAILURE);
}
while ((nread = getline(&line, &len, stream)) != -1)
{
num = strtoull(strtok(line, "\n"), &end_ptr, base);
test_num = 2;
while (num > 0 && test_num != num &&
(num % test_num) != 0)
test_num++;
printf("%lld=%lld*%lld\n", num, num / test_num, test_num);
}
fclose(stream);
free(line);
return (EXIT_SUCCESS);
}