If you put the 23 (25-2 for I & a), into a file named words.txt, a program like this to start with, would make sense, imo:
Code:
#include <stdio.h>
#include <string.h>
int main() {
int i,j, len, n;
char words[23][10];
char text[]={"Edelweiss, edelweiss, \n\tevery morning you greet me.\n\
Small and white, clean and bright, \n\tyou look happy to meet me.\n\
Blossom of snow, may you bloom and grow, \n\tbloom and grow, forever.\n\
Edelweiss, edelweiss, \n\tbless my homeland forever."};
char c;
FILE *fp;
n=0;
fp=fopen("words.txt","r");
if(fp==NULL) {
printf("Error opening words.txt\n");
return 1;
}
for(i=0;i<23;i++) {
fgets(words[i], sizeof(words[0]), fp);
len = strlen(words[i]);
if(words[i][len-1]=='\n') { //remove the newline, & shorten the word
words[i][len-1]='\0'; //by one char
}
printf("\n%s", words[i]);
}
printf("\n\t\t\t press enter to continue\n");
printf("\n %s", text);
fclose(fp);
printf("\n\n\t\t\t press enter when ready\n");
(void) getchar();
return 0;
}
You probably know the song, but here's a nice duet with Julie Andrews and some Henry John fella you might know:
YouTube - Edelweiss: John Denver and Julie Andrews
The purpose of the text[] array is to use it as a trial content for separating words. If you can separate words in a char array, then you'll have very few problems separating words in a file.
And that's the next part of the program - separating the words of the song lyrics in text[]. The strtok() function (part of string.h), can do this, but so will two while loops, as in this pseudo code:
Code:
char one[16]={""};
int i = 0
while(text[i] != '\0') { //while not at the end of the string
j assigned to 0;
while(text[i] != ' ' and text[i] != '\0') {
one[] of j assigned the value of text[] of i
increment i and j
end of while
one of j assigned '\0' //make one a legit string
print one[]
assign one[] of 0, the end of string char: '\0'
++i;
end of while
That's the pseudo logic basics. If your text[] is formatted differently, you'll need to change this logic, of course.