无法编译C文件

时间:2013-10-15 05:06:11

标签: c compilation

我的程序由于某种原因没有编译。我有2个C文件,我按以下方式编译它们:gcc showxbits.c xbits.c -o showxbits -lm。另外,我收到以下错误:

showxbits.c: In function ‘main’:
showxbits.c:18:3: warning: incompatible implicit declaration of built-in function ‘strcpy’ [enabled by default]

我的第一个文件名为xbits,它位于以下位置:

/*
 *  stubs for functions to study
 *  integer-hex conversions
 *
 */

#include <stdio.h>
#include <math.h>
#include "xbits.h"
/*#include "/home/carl/Programs/C/lab2/cheungr/hw2/solution/reverse.c"
/* function represents the int n as a hexstring which it places in the
hexstring array */



void itox( char hexstring[], int n) {
    hexstring[2*sizeof(n) + 1];
    int ratio, remainder;
    int i = 0;
    while( ratio  != 0 )
    {

        ratio = n / 16;
        remainder = n % 16;
        if (remainder == 10){
            hexstring[i] = 'A';
            i++;
        }
        else if (remainder == 11){
            hexstring[i] = 'B';
            i++;
        }
        else if (remainder == 12){
                        hexstring[i] = 'C';
            i++;
                }
        else if (remainder == 13){
                        hexstring[i] = 'D';
            i++;
                }
        else if (remainder == 14){
                        hexstring[i] = 'E';
                    i++;
        }
        else if (remainder == 15){
                        hexstring[i] = 'F';
                    i++;
        }
        else 
            hexstring[i] = remainder;

    }   
    i++;
    hexstring[i] = '\0';
    printf("in itox, processing %d\n",n);
}

/* function converts hexstring array to equivalent integer value  */

int xtoi( char hexstring[]) {
    int i, integer;
    int length = strlen1(hexstring);
    for ( i = length-2 ; i >= 0 ; i--)
    {
         integer += (int) pow((float) hexstring[i] , (float) i);
    }
    /*printf("in xtoi, processing %s\n", hexstring);*/
    return integer;
}

int strlen1 (char line[])
{
        int i;

        i=0;
        while (line[i])
                ++i;
        return i;
}

和我的第二个文件如下:

/*
 *  stub driver for functions to study integer-hex conversions
 *
 */

#include <stdio.h>
#include "xbits.h"

#define ENOUGH_SPACE 1 /* not really enough space */

int main() {
  char hexstring[ENOUGH_SPACE];
  int m=0, n = 0x79FEB220;
  itox( hexstring, n);


  /* for stub testing: create a fake input string */
  strcpy( hexstring, "6BCD7890"); 
  m= xtoi(hexstring);

  printf("\t%12d %s %12d\n", n,hexstring, m);

  return 0;  /* everything is just fine */
}

1 个答案:

答案 0 :(得分:5)

#include <string.h>放入您的计划中。与strcpy()相关的字符串相关函数在该头文件中声明。