编译器错误:对'print'的未定义引用

时间:2015-07-10 07:34:09

标签: c compiler-errors

在我的代码中,我在尝试编译时继续遇到这些错误

  

/tmp/ccshIakV.o:在函数`main':

     

project2.c :(。text + 0x370):对'print'

的未定义引用      

collect2:错误:ld返回1退出状态

这是我的代码

int main(void)
{
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double e = 0;
double f = 0;
double g = 0;
double h = 0;
double i = 0;

char command = '\0';

printf("\n      Welcome\n");
printf("     Aquapodz Stress Analysis Program\n");
printf("    ==================================\n");
while (command != 'x');
    {
printf("\n\n(a), (b), or (c), enter trial data for vendor.\n(f)ail-rate,     (m)ean stress, (s)ummary, e(x)it\n");
printf("Please enter a command");
scanf("%c", &command);

if (command == 'a')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
}
else if (command == 'b')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &d);
scanf("%lf", &e);
scanf("%lf", &f);
}
else if (command == 'c')
{
printf("Please enter stress values (GPa) for this trial.");
scanf("%lf", &g);
scanf("%lf", &h);
scanf("%lf", &i);
}
else if (command == 'f')
{

printf("Average failure rate:\nAzuview:%f\nBublon:%f\nCryztal:%f\n",        a+b+c, d+e+f, g+h+i);
}
else if (command == 'm')
{
printf("Average mean stress:\nAzuview:%f\nBublon:%f\nCryztal:%f\n",     a+b+c/3, d+e+f/3, g+h+i/3);
}
else if (command == 's')
{
print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}
else if (command == 'x')
{

}
else
{
printf("Invalid Command! Please Try Again :)");
}

}
printf("Goodbye, Please Come Again!");
  return 0;
}

我以前从未遇到过这些错误。

5 个答案:

答案 0 :(得分:2)

-Wall -Wextra

仔细看看这部分内容。为避免这种情况,请使用编译器警告(例如,printf()用于gcc) - 在这种情况下,它们会警告隐式函数声明。

另一方面,关于许多其他行:如果没有要格式化的数据,则不需要puts()。如果不存在换行符,请改用fputs()(或stdout- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *identifier; if (indexPath.row %2 == 0) { identifier=@"tablecell"; tablecell *cell = (tablecell*)[tableView dequeueReusableCellWithIdentifier:identifier]; if (cell==nil) { NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"tablecell" owner:self options:nil]; cell=[nib objectAtIndex:0]; } cell.name.text=@"gopi"; return cell; } else if(indexPath.row %2 == 1) { identifier=@"gopicell"; gopicell *cell1=(gopicell*)[tableView dequeueReusableCellWithIdentifier:identifier]; if (cell1==nil) { NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"gopicell" owner:self options:nil]; cell1=[nib objectAtIndex:0]; } cell1.gopilabel.text=@"sabari"; return cell1; } return nil; }

答案 1 :(得分:0)

您的代码中有拼写错误。您错过了f来电中的printf()

你必须改变

else if (command == 's')
{
print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}

else if (command == 's')
{
printf("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
     ^
}

答案 2 :(得分:0)

在此,您需要使用printf而不是print

else if (command == 's')
{
print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)    \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}

答案 3 :(得分:0)

 else if (command == 's')
 {

    print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0)        \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
 }

在这一行中,您排名print而不是printf。请更正

答案 4 :(得分:0)

你错过了{f}到printf

else if (command == 's')
{
    print("Total (pass / fail) so far:\nAzuview:%f(%f/0)\nBublon:%f(%f/0) \nCryztal:%f(%f/0)\n", a+b+c, a+b+c, d+e+f, d+e+f, g+h+i, g+h+i);
}