0

I get error on my source code: "invalid initializer". What am I doing wrong? Someone can help me to resolve this please ?

The errors:
main.c: In function 'main':
main.c:10:8: error: invalid initializer

Thank's for your help : )

EDIT: my program crash when i'm starting it

#include <unistd.h>
#include <stdio.h>
void    ft_putchar(char const c);
char    *ft_strrev(char *str);
void    ft_swap(char *a, char *b);

int     main()
{  
    char *nom;
        nom = ft_strrev("Linsap");

    printf("%s", nom);

    return (0);
}

void    ft_putchar(char const c)
{
    write(1, &c, 1);
}

char    *ft_strrev(char *str)
{
    int longueur;
    longueur = 0;

    while (str[longueur] != '\0')
    {
        ++longueur;
    }

    int i;

    i = 0;
    for (i = 0; i < longueur; ++i)
    {
        ft_swap(&str[i], &str[--longueur]);
    }

    return str;
}

void    ft_swap(char *a, char *b)
{
    char    tmp;
    tmp = *a;

    *a = *b;
    *b = tmp;  
}
  • The code you posted doesn't have compilation problems. What compiler are you using? – Mat May 08 '15 at 20:44
  • 1
    If you're getting an error when you compile, it shouldn't even produce an executable that you can run. – Barmar May 08 '15 at 20:47
  • Which line is line 10 in `main.c`? – Barmar May 08 '15 at 20:48
  • 1
    Your code doesn't match the error you mention, but the crash is due to the same problem as in the linked Q: modifying a string literal. Before posting, make sure that the code you post actually has the problems you describe (compile time or runtime). – Mat May 08 '15 at 20:49

0 Answers0