Home > Back-end >  Function declaration and links
Function declaration and links

Time:11-18

Write a simple addition calculator applet, a total of getline. C, isspace. C, isdigit. C, atof. C, main. C
Always show. But during the compilation of the main c cannot link getline functions, only add getline functions to the main. C to compile properly running behind, I ask you,

Error:



main. C
/* simple addition calculator */
# include
# define MAXLINE 100
Double atof (char [] s);
Int getline (char [] s, int Max);


Int main (void)
{
Char line [MAXLINE];
Double sum=0;

While (getline (line, MAXLINE) & gt; 0 {
Printf (" The sum is % f. \ n ", sum +=atof (line));
}
return 0;
}

//don't add complains!!
/* for a line of string, and store it in array s largest is less than the Max */
/* int getline (char [] s, int Max)
{
Int I, a;

For (I=0; (a=getchar ())!='\ n' & amp; & Max & gt;=0; I++, Max -) {
S [I]=a;
}
If (a=='\ n')
{
S [i++]=a;
}
S [I]='\ 0';

return i;
} */


isspace. C

/* 
If s for Spaces, it returns 1, otherwise return 1
*/

Int isspace (char s)
{
If (s==")
{
return 1;
}

return 0;

}


isdigit. C

//judge if a is a number, if it returns 1, otherwise return 1 

Int isdigit (int a)
{
If (' 0 '& lt;=a & lt;='9')
{
return 1;
}

return -1;
}


atof. C

/* converts a string to a number, for example: "123" is converted to double type 123 */
# include
Int isspace (char a);
Int isdigit (char a);
Double atof (char [] s)
{
Int I, sign;
double val;
For (I=0; [I] isspace (s); I++)
;
Sign=(s [I]=='-')? 1:1;
[I] if (s=='-' | | s [I]=='+')
i++;

for(; [I] isdigit (s); I++) {
Val val +=10.0 * (s [I] - '0');
}
If (s [i++]=='. ')
{
Int k=1;
for(; [I] isdigit (s); I++)
Val=val + [I] - '0' (s)/(pow (10, k));
}

Return val.


}


getline. C

/* for a line of string, and store it in array s largest is less than the Max */

#include
Int getline (char [s], int Max)
{
Int I, a;

For (I=0; (a=getchar ())!='\ n' & amp; & Max & gt;=0; I++, Max -) {
S [I]=a;
}
If (a=='\ n')
{
S [i++]=a;
}
S [I]='\ 0';

return i;
}

CodePudding user response:

System also provides a getline functions, name clashes, don't know which one to link? You put in the main, nature is take function under the same file,

CodePudding user response:

In the name or not, missing link
Undefined reference to ` getLINE_N '
Collect2. Exe: error: ld returned 1 exit status

CodePudding user response:

Is my statement?

CodePudding user response:

reference 1st floor qybao response:
system also provides a getline functions, name clashes, don't know which one to link? You put in the main, is take the nature function, under the same file

In the name or not

CodePudding user response:

https://blog.csdn.net/qq_36965134/article/details/82190801
  • Related