/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

Prueba codigo fuente

 
      Índice del Foro elrincondelc.com -> Pruebas
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
rir3760



Registrado: 01 Oct 2004
Mensajes: 7516
Ubicación: Mexico

MensajePublicado: 03/07/2009 3:17 pm
Título: Prueba codigo fuente

Código:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LONG_CADENA 80
#define CHAR_A_ESCAPAR '\''

int main(void)
{
   char entrada[LONG_CADENA], *salida, *aux;
   int i, j;
   
   printf("Entrada: ");
   fflush(stdout);
   if (fgets(entrada, LONG_CADENA, stdin) == NULL){
      fprintf(stderr, "Error al tratar de leer stdin!\n");
      return EXIT_FAILURE;
   }
   if ((aux = strchr(entrada, '\n')) != NULL)
      *aux = '\0';
   
   if ((salida = malloc(strlen(entrada) * 2 + 1)) == NULL){
      fprintf(stderr, "Error con malloc!\n");
      return EXIT_FAILURE;
   }
   
   for (i = 0, j = 0; entrada[i] != '\0'; i++){
      if (entrada[i] == CHAR_A_ESCAPAR)
         salida[j++] = '\\';
     
      salida[j++] = entrada[i];
   }
   salida[j] = '\0';
   
   printf("Salida: %s\n", salida);
   free(salida);
   
   return EXIT_SUCCESS;
}

_________________
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language
Volver arriba
      Índice del Foro elrincondelc.com -> Pruebas
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com