marcoshuck

Ejercicio 2 - Archivos y cadenas

Oct 31st, 2013
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. /* Nota: Se toma un solo archivo ya creado, el ejercicio pide ingresar el nombre del archivo, esa parte fue omitida */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     int size, i;
  8.     unsigned char flag = 0;
  9.     char m[40];
  10.     FILE * txt;
  11.     txt = fopen("nombres.txt", "rt");
  12.     while(fscanf(txt, "%s", m) == 1 && !feof(txt))
  13.     {
  14.         flag = 0;
  15.         size = strlen(m);
  16.         for(i = 0; i < size/2; i++)
  17.         {
  18.             if(!(m[i] == m[size - 1 - i]))
  19.                 flag = 1;
  20.         }
  21.         if(!flag)
  22.             printf("%s es palindromo.\n", m);
  23.         else
  24.             printf("%s no es palindromo.\n", m);
  25.     }
  26.     system("PAUSE");   
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment