Онлайн компилятор C

#include<stdio.h> const int M=1000; char N(char c) { if(c>=A&&c<=Z) { return c=c+32; } } int main() { int count=0; char str[M+1]; int i=0; char ch; while((ch=getchar())!='\n') { str[i]=ch; i++; } str[i]='\0'; int k=0; while(str[k]!='\0') { while(str[k]=" ") { k++; } if(str[k]=" ") { str[k]=first; } if(str[k]='\0') { k--; str[k]=last; return 0; } } if(first==last) { count++; } printf("%d",count); return 0; }
这段代码试图统计字符串中首尾字符相同的单词数量,但存在多处语法和逻辑错误。

- 字符常量需要用单引号,比如 `'A'`、`'Z'`、`' '`、`'\0'`,而不是直接写 `A`、`Z`、`" "`、`'\0'`。代码中多处使用了双引号或未加引号,这是错误的。
- 变量 `first` 和 `last` 没有定义,也没有赋值。你需要先确定每个单词的首字符和尾字符,然后才能比较它们是否相等。
- 函数 `N` 没有被调用,而且它的参数和返回值类型与使用方式不匹配。如果你想用这个函数转换大小写,需要在主函数中调用它。