Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * lee palabras.c
- *
- * Copyright 2011 Erick Merino Menares <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- *
- */
- #include <stdio.h>
- int main()
- {
- int i, cont;
- int j=0;
- int ch;
- char Palabra[100][50];
- char nombre[100];
- char buscar[100];
- int rebusq[100];
- int cont2=0;
- int drebusq[100];
- FILE *f1;
- printf("Ingrese el nombre del archivo: ");
- scanf("%s", nombre);
- f1=fopen(nombre, "r");
- if(f1==NULL)
- {
- printf("Error, no existe el archivo");
- exit(0);
- }
- else
- {
- cont=0;
- while((ch=getc(f1))!=EOF)
- {
- i=ch;
- if(((i>=65) && (i<=90)) || ((i>=97) && (i<=122))) //65 al 90 mayusculas y 97 al 122 minusculas no acepta acentos (no los lee).
- {
- Palabra[cont][j]=(char)(ch);
- j++;
- }
- else
- {
- if(ch==((int)(' ')))
- {
- cont++;
- j=0;
- }
- }
- }
- }
- printf("La cantidad de palabras son: %d\n", cont+1);
- for(i=0;i<=cont;i++)
- {
- for(j=0;j<50;j++)
- {
- printf("%c", Palabra[i][j]);
- }
- printf(" ");
- }
- printf("\nIngrese la palabra a buscar: ");
- scanf("%s", buscar);
- for(i=0;i<=cont;i++)
- {
- for(j=0;j<50;j++)
- {
- if(buscar[j]!=Palabra[i][j])
- {
- rebusq[i]=-1;
- }
- }
- }
- for(i=0;i<=cont;i++)
- {
- if(rebusq[i]!=-1)
- {
- drebusq[cont2]=i;
- cont2++;
- }
- }
- if(cont2==(cont+1))
- {
- printf("La palabra no está\n");
- }
- else
- {
- printf("La palabra está en las posiciones:");
- for(i=0;i<cont2;i++)
- {
- printf(" %d", drebusq[i]+1);
- }
- printf("\n");
- }
- fclose(f1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment