Answer the question
In order to leave comments, you need to log in
Find the minimum length of a word in C
Stuck on a simple task.
The input is txt with a string (up to 200 characters), you need to find the minimum word length in this string. A sequence of English letters is considered a word (here is the question, a single character cannot be a sequence, can it?).
Navayal quickly the following:
The usual sentence like "Hello, the world!" considers normal (the specially added). However, if the line does not start with a letter, or ends with a letter, or some other unnatural garbage, then it is considered crooked. And it is necessary that all sequences be considered, regardless of their location.
#include "stdafx.h"
#include <stdio.h>
int main()
{
freopen("input.txt","r",stdin);
char c;
int n = 0;
int min = 1000;
while (scanf("%c", &c) == 1)
{
if(isalpha©)
n++;
else
{
if(n<min && n>1)
min=n;
n=0;
}
}
printf("%d", min);
fclose (stdin);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Couldn't reproduce "considered crooked" errors:
#include <stdio.h> #include <ctype.h> int main() { freopen("input.txt","r",stdin); char c; int n = 0; int min = 1000; while (scanf("%c", &c) == 1) { if(isalpha©) n++; else { if(n<min && n>1) min=n; n=0; } } printf("%d", min); fclose(stdin); return 0; }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question