#include <stdio.h> #include <string.h> int main(){ char c[20], result[50]; int bool = 0, count = 0, i; while(fgets(c,20,stdin) != NULL){ int stringSize = strlen(c); if(stringSize == 11){ int ascii = (int)(c[i]); for(i = 0; i < stringSize; i++){ if(ascii >= 'A' && ascii <= 'Z'){ bool = 1; } } } } if(bool == 1){ count++; strcat(result,c); } printf("%d", count); printf("%s",result); } Good morning, I am fairly new to programming, and I've spent quite a while Googling and searching around for this issue already, but I can't seem to wrap my head about it. Basically I'm trying to filter an fgets so that it reads each string, and if they're capital letters, they're "valid". However, I can't even get the fgets to stop accepting more input.
Edit: The idea is to store in result every String that has 10 capital letters, and for the fgets while loop to break once the user gives no input ('\0')
int ascii = (int)(c[i]);usesiuninitialized. It looks like this statement should be in the loop, not before.fgetsloop (not outside the loop). Then if any character isn't upper case, set the flag. But the problem statement isn't clear - please show an example input and required output.int bool = 0. There is a typeboolinstdbool.hAs soon as you need this for other purposes, your code will break. You should not use identifiers that are defined by C standard even if you don't yet include the related headers.