Gaia@home

A simple C code for a single CPU

 

Example Code

Example code that counts the number of lines in the input file with the symbolic name in0:

 

#include <stdio.h>

int main(void)
{
   FILE *input,*output;
   int counter = 0;
   char one_char;

   if((input = fopen("in0", "r")) == NULL)
   {
      printf("Can't open file in0\n",);
      return 1;
   }

   while((one_char = getc(input)) != EOF)
   {
      if(one_char == '\n')
         ++counter;
   }
   fclose(input);

  output=fopen("out","w");
  fprintf(output,"%d\n", counter);
  fclose(output);
  return 0;
}

Produce the executable file:

gcc application.c -o Gaia@home_application



 

Article Details

Article ID:
19
Rating :