Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Redefinition of main

I started writing code in C, and I needed the toupper function in my code, so I added to ctype.h header file to include it.

All of a sudden I can't run my program because I keep getting a redefinition of main error from my compiler.

Before I added the header ctype.h, and even if I get rid of the header file ctype.h, the program runs. What do I do to fix this?

#include <stdio.h>
#include <ctype.h>

#define NAMESPACE 20

int main (void)
{  

    char first_name[NAMESPACE], middle_name[NAMESPACE], last_name[NAMESPACE];
    printf ("Please enter your first, middle and last name.\n");
    scanf ("%s", first_name);
    scanf("%s", middle_name);
    scanf ("%s", last_name);
    printf ("%s %0.1s %s", first_name, middle_name, last_name);
    return 0;
}

[error] redefinition of "int main()":

Here is the code saved as a header file called ctype.h in my DEV c++ ,

#include<stdio.h>
#include<conio.h>
int main (void)
{
char ch[]="I AM AN IDIOT.";
char c='A';
int i=0;
while(c)
{
c=getch();
printf("%c\a",ch[i]);
i++;
if(i==14)
{
printf(" "); i=0;
}
}
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The code you posted does not explain the error message you presented. It has some issues, but none that should elicit any error. There are several possible reasons for the error, among them:

  1. My best guess would be that you have another source file in the project that has its own main() function, and the IDE is configured to include both in the same target program. That might result simply by virtue of them being collocated in the same directory. That other source file might even be something dumb, such as a backup copy of the file you presented.
  2. Alternatively, it may be that you have a project-local header named ctype.h, which defines a main() function, and Dev C++ is choosing that one instead of the standard library's header. (Yes, this is really just a variant on (1); there's not much leeway in "redefinition of 'int main()'".)
  3. Or perhaps Dev C++ misspoke, and it's complaining about a redeclaration of main() rather than a redefinition. If its ctype.h header contained a conflicting declaration, such as int main(int argc, char *argv[]), then it might issue a complaint. In that unlikely case, you might be able to resolve the error by changing the declaration of your main() to the two-argument form.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda