Обсуждение: problem compiling c-functions

Поиск
Список
Период
Сортировка

problem compiling c-functions

От
Aravind Babu Guntha
Дата:
i am trying to compile the below c-program.but iam getting the errors as

/usr/lib/crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status




#include <stdio.h>
#include <stdlib.h> /* required for atoi */

int main() {
  char c[10];
  int sum = 0;
  FILE *file;

  file = fopen("numbers3.txt", "r");

  if(file==NULL) {
    printf("Error: can't open file.\n");
    return 1;
  }
  else {
    printf("File opened successfully.\n");

    while(fgets(c, 10, file)!=NULL) {
      sum += atoi(c); /* convert string to int then add it to sum */
    }

    printf("Now closing file...\n");
    fclose(file);
    printf("The sum of the numbers is: %d\n", sum);
    return 0;
  }
}

could anyone please help me in  solving this problem


Re: problem compiling c-functions

От
Oliver Elphick
Дата:
On Tue, 2002-12-10 at 14:44, Aravind Babu Guntha wrote:
> i am trying to compile the below c-program.but iam getting the errors as
>
> /usr/lib/crt1.o(.text+0x18): In function `_start':
> : undefined reference to `main'
> collect2: ld returned 1 exit status

You need to show us the command line you are using to compile it.

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "The spirit of the Lord GOD is upon me; because the
      LORD hath anointed me to preach good tidings unto the
      meek; he hath sent me to bind up the brokenhearted, to
      proclaim liberty to the captives, and the opening of
      the prison to them that are bound."
                                        Isaiah 61:1