I have a text file, and it is a paragraph with quotation marks, commas, periods, and spaces. I want my C program to scan only the letters into an array, while also making all of them lower case in the process. So if a text file said "Hello.", then the array would have: hello
Asked
Active
Viewed 82 times
0
-
1Read characters. Take only the "correct" ones. Convert to lowercase if needed. – Eugene Sh. Jun 27 '18 at 21:12
-
Say hello to the `switch` statement. – tadman Jun 27 '18 at 21:13
-
2@tadman Why `switch`? `isalpha` + `tolower`. Done. – Eugene Sh. Jun 27 '18 at 21:14
-
@EugeneSh. Periods and spaces? Wasn't sure if those would have special meaning or not. – tadman Jun 27 '18 at 21:14
-
Your program will feature these elements: `getchar()`, `if()`, `isalpha()`, `tolower()`, and `array[i++]`. I leave it to you to combine these elements appropriately. :-) – Steve Summit Jun 27 '18 at 21:15
-
Please show what you have tried. There are hundreds of SO questions along these lines, for you to find. – Weather Vane Jun 27 '18 at 21:21
1 Answers
1
There are multiple solutions. Two of the more "common" would be
Read everything into memory, then copy only the wanted characters to the main array while converting to lower-case.
Read character by character, saving only the characters you want to save while converting to lower-case.
Both of these solutions are basically the same, they only differ in the actual file-reading part.

Some programmer dude
- 400,186
- 35
- 402
- 621