CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Unir caracteres en una variable

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gendrick



Joined: 11 Feb 2008
Posts: 8
Location: MATURIN, VENEZUELA

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

Unir caracteres en una variable
PostPosted: Mon Feb 11, 2008 10:32 am     Reply with quote

Quisiera que me ayudaran a introducir en la

variable Dato
los caracteres de alguna de las palabra que

componen la oración, GRACIAS

Code:
#include <16f876A.h>
#fuses NOPROTECT,NOCPD,NOLVP,NOWDT,XT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <string.h>
#include <input.c>

#use fast_io (A)
#use fast_io (B)

//char Dato[16];
 
void SepararPalabras (char *Entrada)   //[35])
{
int Inicio;     /* Señalará la posición de comienzo de una palabra */
int Pos;        /* Usaré esta variable para irrecorriendo el vector */
char Dato[16]; // los datos se pueden cambiar no lo poscion de mem
char K[8]; //="Paz"; //Con [4]imprime Hasta la mesa, sin [4]imp la P
 
Pos = Inicio = 0;    /* Comienzo en el principio del vector */
 
do{
     /* Si encuentro un caracter espacio punto o fin de texto,
         llegué al final de una palabra */
     if (Entrada[Pos] == ' ' || Entrada[Pos] == '.' || Entrada[Pos] == 0)
     //if (Entrada[Pos] == '.')
        {
         /* Me fijo que la palabra no empiece y termine en la misma
             posición, lo que ocurriría si el string estuviese vacío o si
             hubiesen varios espacios juntos */
        if (Inicio != Pos)
          {
             /* Imprimo uno a uno los caracteres de la palabra */
           while (Inicio < Pos)
           {
             strcpy(Dato, Entrada[Inicio]); //[Inicio]);// se imprimio Entradas
             delay_ms(500);
             printf ("%c", Entrada[Inicio]);
             ++Inicio;
           }
                 /* Salto al siguiente renglón */
           printf ("\n\n\r");
        }
              /* Señalo el comienzo de la siguiente palabra */
        Inicio = Pos+1;
     }
     ++Pos;
   }while (Entrada[Pos-1] != 0);

// Hsta aqui el programa trabaja bien
// Quisiera unir los caracteres pero me inprime unos cracteres erroneos
       
//strcpy(K, *Entrada[0]);
//strcpy(Dato, "Entrada"); 
//*Entrada[2]);

strcat(Dato, Entrada[3]);  //la mes escribio con 3 y 4
strcat(Dato, Entrada[4]);
strcat(Dato, Entrada[2]);

printf ("%s", Dato);
delay_ms(500);  //++K;       
}
 

void main(void)
{
   char Texto[35] = "el gato esta arriba de la mesa.";
   printf ("Las palabras que componen la oracion '%s' son:\n\r", Texto);
   SepararPalabras (Texto);
   //printf ("%s", Dato);// Aqui se imprime dos basura
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 12:10 pm     Reply with quote

Nuestro Español no es bueno. Por favor escribe en Inglés.
(Our Spanish is not good. Please write in English).

Have a look at the standard C function strtok(). The example in the manual is doing exactly what you want.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group