This program is written in C I need help to change the prog

This program is written in C . I need help to change the program to where it reads from an array instead of a manually inputing it.

#include <stdio.h>
#include <stdlib.h>
#define incharacter(char) char = getchar();
#define outcharacter(char) putchar(char)
#define true 1
#define false 0
#define NL \'\ \'
#define BL \' \'
#define MAXPOS 20 // sets the max number

int Alarm;

int main()
{
   int bufpos, fill, CW, k, buffer[MAXPOS+1];
  
   setbuf(stdout,0); //turns off buffering

   Alarm = false;
   bufpos = 0;
   fill = 0;
   do {
  
       incharacter(CW);  
      
          
       if (CW == BL || CW == NL || CW == EOF) {
           if (bufpos != 0) {
               if (fill + bufpos < MAXPOS && fill != 0) {
                   outcharacter(BL);
                   fill = fill +1;
               }
               else {
                   outcharacter(NL);
                   fill = 0;
               }
               for (k=1; k<=bufpos; k++)
                   outcharacter(buffer[k]);
               fill = fill + bufpos;
               bufpos = 0;
           }
       }                  
       else
           if (bufpos == MAXPOS)
               Alarm = true;
           else {
               bufpos = bufpos + 1;
               buffer[bufpos] = CW;
           }
   } while (! (Alarm || CW==EOF) );

                  
   if (Alarm) {
       fprintf(stderr,\"ALARM!! \ \"); exit(1);
   }
   else {
       fprintf(stderr,\"Everything is normal \ \"); exit(0);
   }
}

Solution

#include <stdio.h>
#include <stdlib.h>
#define incharacter(char) char = getchar();
#define outcharacter(char) putchar(char)
#define true 1
#define false 0
#define NL \'\ \'
#define BL \' \'
#define MAXPOS 20 // sets the max number

int Alarm;

int main()
{
   int bufpos, fill, CW, k, buffer[MAXPOS+1];
  
   setbuf(stdout,0); //turns off buffering

   Alarm = false;
   bufpos = 0;
   fill = 0;
   do {
  
       incharacter(CW);  
      
          
       if (CW == BL || CW == NL || CW == EOF) {
           if (bufpos != 0) {
               if (fill + bufpos < MAXPOS && fill != 0) {
                   outcharacter(BL);
                   fill = fill +1;
               }
               else {
                   outcharacter(NL);
                   fill = 0;
               }
               for (k=1; k<=bufpos; k++)
                   outcharacter(buffer[k]);
               fill = fill + bufpos;
               bufpos = 0;
           }
       }                  
       else
           if (bufpos == MAXPOS)
               Alarm = true;
           else {
               bufpos = bufpos + 1;
               buffer[bufpos] = CW;
           }
   } while (! (Alarm || CW==EOF) );

                  
   if (Alarm) {
       fprintf(stderr,\"ALARM!! \ \"); exit(1);
   }
   else {
       fprintf(stderr,\"Everything is normal \ \"); exit(0);
   }
}

This program is written in C . I need help to change the program to where it reads from an array instead of a manually inputing it. #include <stdio.h> #in
This program is written in C . I need help to change the program to where it reads from an array instead of a manually inputing it. #include <stdio.h> #in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site