atoi()将输出设为0尽管字符串有整数

Pra*_*hra -2 c

这是代码:

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

 int main() //main function
 {   
     // Body of the main function starts here.
     double c5,c0,semitone_ratio,frequency; //Defining the middle C, the lowest  note in MIDI, the ratio and frequency.

     char message[256];
     int midinote = 0;
     char* result;
     semitone_ratio = pow(2,1/12.0); //Calculating the semitone ratio.
     c5 = 220.0 * pow(semitone_ratio, 3); //Calculating the Middle C Frequency using A5 = 440 Hz and raising it up 3 notes.
     c0 = c5 * pow(0.5,5);             //Calculating C0 by shifting it down 5 octaves

     //User Interface
     printf("Enter MIDI note (0-127) : \n");
     scanf("%s", message);
     printf("%s", message);

     if(result == NULL){
         printf("There was an error reading the input");
         return 1;
     }

     if(message[0] = '\0') {
         printf("No input detected");
         return 1;
     }

     midinote = atoi(message);

     if(midinote <0){
         printf("Sorry - %s is a bad MIDI note number", message);
         return 1;
     }

     if(midinote > 127)
     {
         printf("Sorry - %s is above the range needed", message);
     }

     frequency = c0 * pow(semitone_ratio, midinote);
     printf("The frequency  for the %d MIDI note is %f\n",midinote,frequency);

     return 0;
}
Run Code Online (Sandbox Code Playgroud)

这里的问题是,尽管我输入的任何消息,O/P总是0.我已经尝试过scanf()而不是gets()结果而不是消息(char *而不是char[]- >处理const问题)但是同样的错误.我究竟做错了什么?

Joh*_*ica 5

if (message[0] = '\0') {
    printf("No input detected");
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

使用==.

if (message[0] == '\0') {
    printf("No input detected");
    return 1;
}
Run Code Online (Sandbox Code Playgroud)