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

Write a C program that takes 3 values as strings from the command line. Your pro

ID: 3567502 • Letter: W

Question

Write a C program that takes 3 values as strings from the command line. Your program must implement the following functions.
                 a) int getDataType(char *num)
                 b) void printValue(char *num, int dataType)

getDataType will take a string as input and return 1 if the number is an int and 2 if the number is a double. (hint: check for a

Write a C program that takes 3 values as strings from the command line. Your program must implement the following functions. a) int getDataType(char *num) b) void printValue(char *num, int dataType) getDataType will take a string as input and return 1 if the number is an int and 2 if the number is a double. (hint: check for a ?????.????? in the string) printValue takes the pointer to character array and data type as input and uses either the atoi or atof function to print out the value. Your main function should loop through the input values in argv where on each value it will check the data type and print out the value using the two functions above. Sample output screenshot:

Explanation / Answer

#include <stdio.h>
#include <string.h>

int getDataType(char *num){
   int i;
   for(i = 0; i < strlen(num); i++){
       if(num[i] == '.') return 2;
   }
   return 1;
}

void printValue(char *num, int dataType){
   if(dataType == 1) printf("%d ", atoi(num));
   else if(dataType == 2) printf("%f ", atof(num));
}

int main(int argc, char *argv[]){
   int i;
   for(i = 1; i <= 3; i++){
       printf("argv[%d] = ", i);
       printValue(argv[i], getDataType(argv[1]));
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote