From c853da4c658967104be63335b79d217a2e67cb38 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Wed, 25 Jan 2012 06:12:46 +0100 Subject: [PATCH] now with fileread --- openmp/prefix/prefix.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/openmp/prefix/prefix.c b/openmp/prefix/prefix.c index 246d3e5..c0f0956 100644 --- a/openmp/prefix/prefix.c +++ b/openmp/prefix/prefix.c @@ -72,7 +72,7 @@ int main (int argc, char* argv[]) { stat(filename, &st); size = st.st_size; if (n == -1 || n > size){ - // n = size; //TODO: uncomment after reading file is implemented! + n = size; } }else{ fprintf (stderr, "File %s does not exist.\n", filename); @@ -90,12 +90,18 @@ int main (int argc, char* argv[]) { fprintf(stderr, "malloc for numarray sucessful.\n"); } - /* read file. TODO */ - size = n-1; - for (size = 0; size < n; size++) { - numarray[size] = 10; + /* read file. */ + if ((file = fopen(filename, "r"))) { + for (size = 0; size < n; size++) { + numarray[size] = fgetc(file); + } + fclose(file); + }else{ + fprintf (stderr, "File %s could not be read.\n", filename); + usage(); } - fprintf(stderr, "TODO: file read (set all = 10 for now) - ready.\n"); + + fprintf(stderr, "file read - ready.\n"); #ifdef DEBUG /* might want to comment this out, if numarray is big */ -- 2.43.0