我的程序由于某种原因没有编译。我有 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 */
}