mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
added stdint.h for fixed width ints
This commit is contained in:
parent
fe5c6a724d
commit
6a09ade47d
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int64_t get_product(FILE *fp, long start_pos, int num_digits)
|
int64_t get_product(FILE *fp, long start_pos, int num_digits)
|
||||||
@ -9,7 +10,7 @@ int64_t get_product(FILE *fp, long start_pos, int num_digits)
|
|||||||
int count = 0; /* we use this variable to count number of bytes of file read */
|
int count = 0; /* we use this variable to count number of bytes of file read */
|
||||||
|
|
||||||
/* accumulate product for num_digits */
|
/* accumulate product for num_digits */
|
||||||
for(int i = 0; i < num_digits; i++, count++)
|
for (int i = 0; i < num_digits; i++, count++)
|
||||||
{
|
{
|
||||||
/* get character from file */
|
/* get character from file */
|
||||||
ch = getc(fp);
|
ch = getc(fp);
|
||||||
@ -44,8 +45,7 @@ int64_t get_product(FILE *fp, long start_pos, int num_digits)
|
|||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
{
|
||||||
int position = 0;
|
int position = 0;
|
||||||
int num_digits = 4;
|
int num_digits = 4;
|
||||||
@ -77,7 +77,7 @@ int main(int argc, char* argv[])
|
|||||||
max_prod = prod;
|
max_prod = prod;
|
||||||
position = ftell(fp) - 1;
|
position = ftell(fp) - 1;
|
||||||
}
|
}
|
||||||
} while(!feof(fp)); /* loop till end of file is reached */
|
} while (!feof(fp)); /* loop till end of file is reached */
|
||||||
|
|
||||||
printf("Maximum product: %lld\t Location: %d^th position\n\t", max_prod, position);
|
printf("Maximum product: %lld\t Location: %d^th position\n\t", max_prod, position);
|
||||||
fseek(fp, position, SEEK_SET); /* move cursor to identified position in file */
|
fseek(fp, position, SEEK_SET); /* move cursor to identified position in file */
|
||||||
|
Loading…
Reference in New Issue
Block a user