I have a problem with an homework. I need to read strings from file and i need to find words that begin with a Capital Letter, and i need to write these in a new vector. The step 1 is done, i need to use function for these steps, and i can't use library except <stdio.h>
Example:
Original String: the Pen is Red New Vector: Pen, Red
My code:
#include <stdio.h>
#define dim 150
void lettura(int vett1[]); // reading function
void capitalLetter(int vett1[], int vett2[], int i);
main()
{
char vett1[dim];
char vett2[dim];
int i;
lettura(vett1);
capitalLetter(vett1, vett2, i);
}
void lettura(int vett1[])
{
FILE *fp;
char nomefile[dim];
printf("--> Inserisci il nome del file: \n\n", &nomefile); // "insert the name of the file"
gets(nomefile);
printf("\n--> Il contenuto del file e' il seguente: \n\n"); // "the content of the file is the following"
fp= fopen("file.txt","r");
while(!feof(fp)) {
fgets(vett1, dim, fp);
printf("%s", vett1);
} // I close the while
fclose(fp);
} // I close the function
void capitalLetter(int vett1[], int vett2[], int i)
{
for(i=0; i<dim; i++){
if((vett1[i]>= 'A') && (vett1[i]<= 'Z'))
vett1=vett2;
}
printf("%s", vett2);
}