如何将文本字符串转换为C中的int以查找其中的部分?

My current issue with this code has to do with the Punctuation Count if statement if(Text == '.' || Text == '!' || Text == '?').

Is there a variable I can create to replace Text in this situation and allow the code to run its process?

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


int main(void)
{  //Letter Count Section
string Text = get_string("Text: "); //Gets Text
char Checker = isalpha(Text); // Checks for letters
int Count = strlen(&Checker); //Counts letters

//Space Count Section
 int Spaces = 0; //Declares Variable
if(isspace(Text)){ //Checks for Spaces
 Spaces += 1; //Adds +1 to Variable if Space
}

//Punctuation Count
 if(Text == '.' || Text == '!' || Text == '?')
 Punctuation += 1;

float Sentence = (Count/(Spaces*100));
float Letters = (Punctuation/(Spaces*100));
 printf("\n%f",Sentence);
 printf("\n%f",Letters);

 // Formula  
    int gradelvl = (0.0588 * Letters - 0.296 * Sentence - 15.8);
 // End Result  
        printf("\nGradelevel: %i\n",gradelvl);
}
评论
  • cut
    cut 回复

    在这种情况下,是否可以创建一个变量来替换Text并允许代码运行其过程?
      char c = Text[0];