error: redefinition of ‘main’ [solution.c] int main(int argc, char *argv[]) { | ^~~~ Can anyone kindly explain where I am wrong?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deba2005
    • Aug 2024
    • 2

    error: redefinition of ‘main’ [solution.c] int main(int argc, char *argv[]) { | ^~~~ Can anyone kindly explain where I am wrong?

    #include<stdio. h>

    int main()
    {

    printf("Enter number of term: ");
    int n;
    scanf("%d", &n);
    int nums[n];
    int counter=0;

    for(int i=0; i<n; i++)
    scanf("%d", &nums[i]);

    printf("Enter Target: ");
    int target;
    scanf("%d", &target);

    for(int i=0; i<n; i++)
    {
    for(int j=0; j<n; j++)
    {
    if(i==j)
    continue;

    if(target==nums[i]+nums[j])
    {
    printf("(%d,%d) ", i, j);
    counter++;
    }
    }
    if(counter==1)
    break;
    }
    return 0;
    }
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    error: redefinition of ‘main’ [solution.c] int main(int argc, char *argv[]) { | ^~~~ Can anyone kindly explain where I am wrong?
    Code:
    #include<stdio. h>
    
    int main()
    {
    
    printf("Enter number of term: ");
    int n;
    scanf("%d", &n);
    int nums[n];
    int counter=0;
    
    for(int i=0; i<n; i++)
    scanf("%d", &nums[i]);
    
    printf("Enter Target: ");
    int target;
    scanf("%d", &target);
    
    for(int i=0; i<n; i++)
    {
    for(int j=0; j<n; j++)
    {
    if(i==j)
    continue;
    
    if(target==nums[i]+nums[j])
    {
    printf("(%d,%d) ", i, j);
    counter++;
    }
    }
    if(counter==1)
    break;
    }
    return 0;
    }
    It happens when there is more than one definition of main. The main function appears only once in the posted code. Have you included the complete code? Are there any other files being linked?

    Comment

    Working...