Question:
Help in C why am i getting these errors?
Dan
2010-02-19 00:37:20 UTC
I have finished this program, obviously i haven't but i thought i had, am getting these errors, this is my first time trying to make a file in C, and iam getting these errors why?

/tmp/ccEcsWOr.o: In function `main':
chapter10_1.c:(.text+0x21): undefined reference to `getint'
collect2: ld returned 1 exit status




my code is

#include

#include


main()

{



struct details

{

FILE *fp;

char name;

int number;

int quantity;

char letter;

}details;



printf("Information is here \n");



details.name = getchar();

details.number = getint();

details.quantity = details.name && details.number;



details.fp = fopen("stock.dat","w");



fprintf(details.fp,"%s EOL %d EOL %d EOL",details.name,details.number,details.quantity);



fclose(details.fp);



}


could you alter my code seeing as how i dont know what else to do.
Thanks for the help
Three answers:
jplatt39
2010-02-19 01:43:53 UTC
Something is screwy here. When I see /tmp/ccEcsWOr.o: and (.text+0x21) I expect to see:



collect2: ld returned 1 exit status



This is a linker error not a syntax error. In essence that means that the preprocessor found a header file which contains getint() and set aside space to link to it in libc (which is the standard C library always linked to when you #include files from stdio.h or stdlib.h which stdio.h calls). Either you called getint() in a way which made the compiler set aside memory the wrong way, or there is something wrong with the installation of your libc library. In either case you shouldn't ask here, you should ask your instructor or someone in the computer lab.
2010-02-19 00:48:05 UTC
It doesn't work because "getint()" isn't a defined function. You'll need to write your own function for that :), or, look up "scanf".
MC
2010-02-19 01:27:26 UTC
intstead of details.number = getint();



i would use scanf("%d",&detail.number);



i haven't seen getint() before that looks like a java method,


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...