Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

both the subroutine and the main program are required Problem 2: Write a FORTRAN

ID: 3737027 • Letter: B

Question

both the subroutine and the main program are required

Problem 2: Write a FORTRAN 90 stubroutine named cc that takes as its first argument a two dimensional array of characters named arr with NR rows and NC columns where NR and NC are parameters The second argument to the subroutine is a character string of length 1 named ch. The subroutine source code is in a module in a separate file from the file containing the main program source code. For each row the subroutine prints (on a single line) at the screen the characters in the row up to but not including the first occurrence of the character in ch. If the character in ch does not occur in a row, then all characters in the row are printed on a single line on the screen. Write a main program that uses the subroutine cc. Provide test results for the following data file which the main program opens and reads. (Use values of 5 and 6 for NR and NC respectively 231x56 s3fgtr wxr56t 12x3xx xf3f3e Provide a run with user input character "3" and another run when the input character "1"

Explanation / Answer

int const NR = 1;
int const NC = 1;       //Define the constants
int const NCC = 1;

void cc(char arr[NR][NC],char locations[NCC][2],char ch,int** count)
{
int count1=0;
for(int i=0;i<NR;i++)
   for(int j=0;j<NC;j++)
   {
       if(arr[i][j]==ch)
       {
           locations[i][j]=ch;
           count1++;
       }
   }
   *count = (int*) malloc(sizeof(int));
(*(*count)) = count1;
}


int main()
{


FILE *ptr_file;
char buf[1000];

ptr_file =fopen("input.txt","r");
if (!ptr_file)
        return 1;

while (fgets(buf,1000, ptr_file)!=NULL)
   //handle how the data from the file is to be stored in the array. Details for the same aren't mentioned.
   char ch;
   char locations[NCC][2];
   char arr[NR][NC];
   printf("Enter the character to be searched: ");
   scanf("%c",ch);
  
   int *count=NULL;
   cc(arr,locations,ch,&count);
  

}