How would you write think funcion in C program Write a funct

How would you write think funcion in C program?

Write a function : char* signal_to_message(double* signal, int size); that accepts a noisy signal (as an array) and the size of the array. The output should be a string,i.e., character array with null terminator, that represents the received message.

Solution

#include <stdio.h>

char* signal_to_message(double *signal, int size)   //function definition
{
   printf(\"%lf\",*signal);
   if(*signal < 2.0 )
   return \"little noisy\";
   else if(*signal >=2.0 && *signal<8.0)
   return \"noisy\";
   else if(*signal >8.0)
   return \"very noisy\";
}
int main(void)
{
   char *message;
   double signal[5];
   int i;
  
   for(i=0;i<5;i++)
   {
   printf(\"\ Enter noisy signal: \");
   scanf(\"%lf\",&signal[i]);
   //printf(\"%lf\",signal[i]);
   message = signal_to_message((signal+i),5); //function call
  
   printf(\"\\t%s\",message);
   }
  
   return 0;
}


output:

How would you write think funcion in C program? Write a function : char* signal_to_message(double* signal, int size); that accepts a noisy signal (as an array)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site