Me pase con este tema unas cuantas horas y hasta aquí llegue, espero que me puedan ayudar a resolverlo.-
En primer lugar les pongo el enunciado.
Lo que llevo hecho es lo siguiente.
Código: Seleccionar todo
#include <stdio.h>
#include <string.h>
int main(void){
char tempFrase[] = "La casa de Juan es de color azul", *token, frase[32];
int ocurrencias=0;
strcpy(frase, tempFrase);
token = strtok(tempFrase," ");
while (token != NULL){
printf("\n En la direccion %p se encuentra la palabra...: %s\n", token ,token);
(strlen(token) == 4) ? ocurrencias++ : ocurrencias;
token = strtok(NULL," ");
}
printf("\n La frase \"%s\" contiene %d palabras de 4 letras\n\n", frase, ocurrencias);
return 0;
}
/*
#include <stdio.h>
#include <string.h>
#define MAX_FRASES 5
#define MAX_LONGITUD 30
void verificaIngreso(char frases[][MAX_LONGITUD], int i);
int main(void){
char frases[MAX_FRASES][MAX_LONGITUD];
int i=0, j=0, ocurrencias=0, com=0, fin=0;
for(; i<MAX_FRASES; i++){
printf("\n Ingrece frase[%d]...:", i+1);
fgets(frases[i], MAX_LONGITUD, stdin);
verificaIngreso(frases, i);
}
for(i=0; i<MAX_FRASES; i++){
printf("\n La frase[%d] tiene una longitud de %d caracteres", i+1, strlen(frases[i]));
}
for(i=0; i<MAX_FRASES; i++){
for(j=0; frases[i][j]; j++){
if(frases[i][j] == 32)
com = frases[j]
}
}
printf("\n %d", espacios);
printf("\n\n");
return 0;
}
void verificaIngreso(char frases[][MAX_LONGITUD], int i){
char *p=NULL;
unsigned int ch=0;
if((p=strchr(frases[i], '\n'))!=0){
*p='\0';
}
else{
while((ch = getchar()) !='\n' && ch!=EOF);
}
}*/
Saludos y desde ya muchas gracias por el tiempo.-
Daniel