Что не так в моем коде на языке Си?
Что не так в моем коде на языке Си? Я хочу создать программу, в которой компилятор считывает символы с клавиатуры до тех пор, пока последние три прочитанных символа не составят слово A P H. отобразите количество прочитанных символов. (Читайте не более 25 символов)
и я также не могу заставить его читать символы, введенные иначе, чем APH.
Что я уже пробовал:
#include<stdio.h> #include<string.h> int main() { int i,j,Count=0,length=0; int n=25; // 'n' is for setting Limit of maximum characters to entered char Letters[n]; printf("Enter Characters: "); gets(Letters); while(Letters[length]!=0) // WHILE Loop for counting number of characters entered { length++; } if(length<=n) //IF-ELSE for checking whether the characters------- { // --------------entered are within th limit or not while(i<n) { i=Count; if(Letters[i]=='A' && Letters[i+1]=='P' && Letters[i+2]=='H' && length==Count+3) // IF-ELSE Loop for differentiating between---- { // --------characters having 'APH' in it`s last printf("\n"); Count=Count+3; // Addition of '3' for including 'APH' in counting printf("Characters Read: %d",Count); break; } else { Count=i+1; } } } else { printf("You have entered more than %d characters",n); } }