-4

I receive 3 arguments NaN, +infinity and -infinity and I want to generate manually NaN,+inf,-inf by changing the exponent and the mantissa of the IEEE 754 number. How can I do it and save it after into a float array?

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char*argv[]){

    int n=argc;
    float array[n];
    int i;
    for(i=0;i<n;i++){

       array[i]=argv[i];
       float number = argv[i];
       printf("the array[%f] is : %f",i,number);
    }
    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

0

First of all, remember that argv[0] is the name of the program. You should skip it in your loop.

Then for your problem, the values of the argv array are strings, that you need to convert to floating point values if that's what the supposed arguments are. For converting a string to a floating point value you can use strtof.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621