0
내 프로그램이 어떤 이유로 컴파일되지 않습니다. I 2 개 C 파일을 가지고 있고, 나는 다음과 같은 방식으로 컴파일 :C 파일을 컴파일 할 수 없습니다.
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;
}
gcc showxbits.c xbits.c -o showxbits -lm
.Moreover, 나는 다음과 같은 오류가 내 두 번째 파일은 다음과 같습니다.
/*
* 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 */
}
무엇이 오류입니까? 경고가 컴파일에 실패하지 않습니다 – tristan
처음으로 라이브러리 함수를 사용할 때마다 Google man function_name에 좋습니다. 함수 자체를 사용하는 방법을 가르치는 데 도움이 될뿐만 아니라 라이브러리 함수를 올바르게 사용하는 BTW 부분 인 헤더 파일의 올바른 집합을 포함하여 안내합니다. – smRaj
문자열 함수를 사용하는 동안 #include 헤더 파일을 추가하십시오. –
vkulkarni