[C con Clase] dividir un String
Jose Alvaro Dominguez
ilgrim en gmail.com
Mie Abr 22 11:31:01 CEST 2009
On Wed, Apr 22, 2009 at 7:58 AM, Abel <aydabella en yahoo.com.ar> wrote:
> Hola, podria ayudarme alguien con este código:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> void split (const char* pInput, const char* pOut1, const char* pOut2) ;
>
> int main(void)
> {
> char s1[100]="", s2[100]="";
> split ("Hallo Welt", s1, s2);
> printf ("%s\n", s1);
> printf ("%s\n", s2);
> return EXIT_SUCCESS;
> }
>
> void split (const char* pInput, const char* pOut1, const char* pOut2)
> {
> const char*p = strchr (pInput, ' ');
> if (!p)
> {
> // input contains no ' '
> *pOut1 = '\0';
> *pOut2 = '\0';
> }
> else
> {
> strncpy (pOut1, pInput, p - pInput);
> strcpy (pOut2, p + 1);
> }
> }
>
> Me dá los siguientes errores:
> Assigment to const location
> Assigment to const location
> Type error in argument 1 to 'strncpy';found 'pointer to const char' expected 'pointer to char'
> Type error in argument 1 to 'strncpy';found 'pointer to const char' expected 'pointer to char'
Prueba a cambiar los tipos de la funcion split, igual se soluciona.
Deberia quedar algo tal que asi:
void split ( char* pInput, char* pOut1, char* pOut2)
...
...
...
Un saludo.
Más información sobre la lista de distribución Cconclase