在windows中导入C库
C语言中的basic程序,但我得到以下错误: tcc:错误:未定义符号“GetFloat” 问题是什么?我该如何解决? 我将cs50.c和cs50.h放在与脚本相同的目录中。 以下是我的主要文件:在windows中导入C库,c,cs50,C,Cs50,C语言中的basic程序,但我得到以下错误: tcc:错误:未定义符号“GetFloat” 问题是什么?我该如何解决? 我将cs50.c和cs50.h放在与脚本相同的目录中。 以下是我的主要文件: #include "cs50.h" #include <stdio.h> int main(void) { printf("enter change owed: "); float x = GetFloat(); printf("you entered %f
#include "cs50.h"
#include <stdio.h>
int main(void)
{
printf("enter change owed: ");
float x = GetFloat();
printf("you entered %f\n", x);
}
#包括“cs50.h”
#包括
内部主(空)
{
printf(“输入所欠更改:”);
float x=GetFloat();
printf(“您输入了%f\n”,x);
}
这是cs50.h
/****************************************************************************
* CS50 Library 4
* https://manual.cs50.net/Library
*
* Based on Eric Roberts' genlib.c and simpio.c.
*
* Copyright (c) 2011,
* Glenn Holloway <holloway@eecs.harvard.edu>
* David J. Malan <malan@harvard.edu>
* All rights reserved.
*
* BSD 3-Clause License
* http://www.opensource.org/licenses/BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CS50 nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
#ifndef _CS50_H
#define _CS50_H
#include <float.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
/*
* Our own data type for string variables.
*/
typedef char *string;
/*
* Reads a line of text from standard input and returns the equivalent
* char; if text does not represent a char, user is prompted to retry.
* Leading and trailing whitespace is ignored. If line can't be read,
* returns CHAR_MAX.
*/
char GetChar(void);
/*
* Reads a line of text from standard input and returns the equivalent
* double as precisely as possible; if text does not represent a
* double, user is prompted to retry. Leading and trailing whitespace
* is ignored. For simplicity, overflow and underflow are not detected.
* If line can't be read, returns DBL_MAX.
*/
double GetDouble(void);
/*
* Reads a line of text from standard input and returns the equivalent
* float as precisely as possible; if text does not represent a float,
* user is prompted to retry. Leading and trailing whitespace is ignored.
* For simplicity, overflow and underflow are not detected. If line can't
* be read, returns FLT_MAX.
*/
float GetFloat(void);
/*
* Reads a line of text from standard input and returns it as an
* int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text
* does not represent such an int, user is prompted to retry. Leading
* and trailing whitespace is ignored. For simplicity, overflow is not
* detected. If line can't be read, returns INT_MAX.
*/
int GetInt(void);
/*
* Reads a line of text from standard input and returns an equivalent
* long long in the range [-2^63 + 1, 2^63 - 2], if possible; if text
* does not represent such a long long, user is prompted to retry.
* Leading and trailing whitespace is ignored. For simplicity, overflow
* is not detected. If line can't be read, returns LLONG_MAX.
*/
long long GetLongLong(void);
/*
* Reads a line of text from standard input and returns it as a
* string (char *), sans trailing newline character. (Ergo, if
* user inputs only "\n", returns "" not NULL.) Returns NULL
* upon error or no input whatsoever (i.e., just EOF). Leading
* and trailing whitespace is not ignored. Stores string on heap
* (via malloc); memory must be freed by caller to avoid leak.
*/
string GetString(void);
#endif
/****************************************************************************
*CS50图书馆4
* https://manual.cs50.net/Library
*
*基于Eric Roberts的genlib.c和simpio.c。
*
*版权所有(c)2011,
*格伦·霍洛韦
*大卫·J·马兰
*版权所有。
*
*BSD 3条款许可证
* http://www.opensource.org/licenses/BSD-3-Clause
*
*以源代码和二进制形式重新分发和使用,带或不带
*如果满足以下条件,则允许修改
*会议:
*
**源代码的重新分发必须保留上述版权声明,
*此条件列表和以下免责声明。
**二进制形式的重新分发必须复制上述版权
*请注意,此条件列表和中的以下免责声明
*随分发提供的文件和/或其他材料。
**不得使用CS50的名称或其出资人的名称
*未经授权,支持或推广从本软件衍生的产品
*事先书面许可。
*
*本软件由版权所有人和贡献者“作为
*以及任何明示或暗示的保证,包括但不限于
*对于,对适销性和适用性的默示保证
*特殊用途不作声明。在任何情况下,版权
*持有人或出资人对任何直接、间接、附带、,
*特殊、惩戒性或后果性损害(包括但不限于
*替代商品或服务的采购;使用、数据或服务的丢失
*利润;或业务中断),无论是何种原因造成的
*责任,无论是合同责任、严格责任还是侵权责任(包括
*因使用本文件而产生的任何疏忽或其他原因)
*软件,即使已告知此类损坏的可能性。
***************************************************************************/
#ifndef_CS50_H
#定义_CS50_H
#包括
#包括
#包括
#包括
/*
*我们自己的字符串变量数据类型。
*/
typedef char*字符串;
/*
*从标准输入中读取一行文本并返回等效文本
*炭;如果文本不表示字符,则提示用户重试。
*忽略前导空格和尾随空格。如果这一行无法读取,
*返回CHAR_MAX。
*/
char GetChar(void);
/*
*从标准输入中读取一行文本并返回等效文本
*尽可能精确地加倍;如果文本不代表
*双击,提示用户重试。前导和尾随空格
*被忽略了。为简单起见,不会检测到溢出和下溢。
*如果无法读取行,则返回DBL_MAX。
*/
double-GetDouble(无效);
/*
*从标准输入中读取一行文本并返回等效文本
*尽可能精确地浮动;如果文本不表示浮点,
*系统将提示用户重试。忽略前导空格和尾随空格。
*为简单起见,不会检测到溢出和下溢。如果线路不能
*被读取,返回FLT_MAX。
*/
float GetFloat(无效);
/*
*从标准输入中读取一行文本,并将其作为
*如果可能,int在[-2^31+1,2^31-2]的范围内;如果文本
*不表示这样的整数,系统将提示用户重试。主要的
*并忽略尾随空格。为简单起见,不需要溢出
*检测到。如果无法读取行,则返回INT_MAX。
*/
int GetInt(void);
/*
*从标准输入中读取一行文本并返回等效文本
*如果可能,在[-2^63+1,2^63-2]范围内进行长距离操作;如果文本
*不代表这么长,提示用户重试。
*忽略前导空格和尾随空格。为简单起见,溢出
*未检测到。如果无法读取行,则返回LLONG_MAX。
*/
long-long-getlong(无效);
/*
*从标准输入读取一行文本,并将其作为
*字符串(char*),无尾随换行符。(因此,如果
*用户仅输入“\n”,返回“不为NULL。)返回NULL
*错误或无任何输入(即仅EOF)。主要的
*尾随空格也不会被忽略。在堆上存储字符串
*(通过malloc);调用者必须释放内存以避免泄漏。
*/
字符串GetString(void);
#恩迪夫
最后,这里是cs50.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cs50.h"
/*
* Reads a line of text from standard input and returns the equivalent
* char; if text does not represent a char, user is prompted to retry.
* Leading and trailing whitespace is ignored. If line can't be read,
* returns CHAR_MAX.
*/
char GetChar(void)
{
// try to get a char from user
while (true)
{
// get line of text, returning CHAR_MAX on failure
string line = GetString();
if (line == NULL)
return CHAR_MAX;
// return a char if only a char (possibly with
// leading and/or trailing whitespace) was provided
char c1, c2;
if (sscanf(line, " %c %c", &c1, &c2) == 1)
{
free(line);
return c1;
}
else
{
free(line);
printf("Retry: ");
}
}
}
/*
* Reads a line of text from standard input and returns the equivalent
* double as precisely as possible; if text does not represent a
* double, user is prompted to retry. Leading and trailing whitespace
* is ignored. For simplicity, overflow and underflow are not detected.
* If line can't be read, returns DBL_MAX.
*/
double GetDouble(void)
{
// try to get a double from user
while (true)
{
// get line of text, returning DBL_MAX on failure
string line = GetString();
if (line == NULL)
return DBL_MAX;
// return a double if only a double (possibly with
// leading and/or trailing whitespace) was provided
double d; char c;
if (sscanf(line, " %lf %c", &d, &c) == 1)
{
free(line);
return d;
}
else
{
free(line);
printf("Retry: ");
}
}
}
/*
* Reads a line of text from standard input and returns the equivalent
* float as precisely as possible; if text does not represent a float,
* user is prompted to retry. Leading and trailing whitespace is ignored.
* For simplicity, overflow and underflow are not detected. If line can't
* be read, returns FLT_MAX.
*/
float GetFloat(void)
{
// try to get a float from user
while (true)
{
// get line of text, returning FLT_MAX on failure
string line = GetString();
if (line == NULL)
return FLT_MAX;
// return a float if only a float (possibly with
// leading and/or trailing whitespace) was provided
char c; float f;
if (sscanf(line, " %f %c", &f, &c) == 1)
{
free(line);
return f;
}
else
{
free(line);
printf("Retry: ");
}
}
}
/*
* Reads a line of text from standard input and returns it as an
* int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text
* does not represent such an int, user is prompted to retry. Leading
* and trailing whitespace is ignored. For simplicity, overflow is not
* detected. If line can't be read, returns INT_MAX.
*/
int GetInt(void)
{
// try to get an int from user
while (true)
{
// get line of text, returning INT_MAX on failure
string line = GetString();
if (line == NULL)
return INT_MAX;
// return an int if only an int (possibly with
// leading and/or trailing whitespace) was provided
int n; char c;
if (sscanf(line, " %d %c", &n, &c) == 1)
{
free(line);
return n;
}
else
{
free(line);
printf("Retry: ");
}
}
}
/*
* Reads a line of text from standard input and returns an equivalent
* long long in the range [-2^63 + 1, 2^63 - 2], if possible; if text
* does not represent such a long long, user is prompted to retry.
* Leading and trailing whitespace is ignored. For simplicity, overflow
* is not detected. If line can't be read, returns LLONG_MAX.
*/
long long GetLongLong(void)
{
// try to get a long long from user
while (true)
{
// get line of text, returning LLONG_MAX on failure
string line = GetString();
if (line == NULL)
return LLONG_MAX;
// return a long long if only a long long (possibly with
// leading and/or trailing whitespace) was provided
long long n; char c;
if (sscanf(line, " %lld %c", &n, &c) == 1)
{
free(line);
return n;
}
else
{
free(line);
printf("Retry: ");
}
}
}
/*
* Reads a line of text from standard input and returns it as a
* string (char*), sans trailing newline character. (Ergo, if
* user inputs only "\n", returns "" not NULL.) Returns NULL
* upon error or no input whatsoever (i.e., just EOF). Leading
* and trailing whitespace is not ignored. Stores string on heap
* (via malloc); memory must be freed by caller to avoid leak.
*/
string GetString(void)
{
// growable buffer for chars
string buffer = NULL;
// capacity of buffer
unsigned int capacity = 0;
// number of chars actually in buffer
unsigned int n = 0;
// character read or EOF
int c;
// iteratively get chars from standard input
while ((c = fgetc(stdin)) != '\n' && c != EOF)
{
// grow buffer if necessary
if (n + 1 > capacity)
{
// determine new capacity: start at 32 then double
if (capacity == 0)
capacity = 32;
else if (capacity <= (UINT_MAX / 2))
capacity *= 2;
else
{
free(buffer);
return NULL;
}
// extend buffer's capacity
string temp = realloc(buffer, capacity * sizeof(char));
if (temp == NULL)
{
free(buffer);
return NULL;
}
buffer = temp;
}
// append current character to buffer
buffer[n++] = c;
}
// return NULL if user provided no input
if (n == 0 && c == EOF)
return NULL;
// minimize buffer
string minimal = malloc((n + 1) * sizeof(char));
strncpy(minimal, buffer, n);
free(buffer);
// terminate string
minimal[n] = '\0';
// return string
return minimal;
}
#包括
#包括
#包括
#包括“cs50.h”
/*
*从标准输入中读取一行文本并返回等效文本
*炭;如果文本不表示字符,则提示用户重试。
*忽略前导空格和尾随空格。如果这一行无法读取,
*返回CHAR_MAX。
*/
char GetChar(void)
{
//尝试从用户获取字符
while(true)
{
//获取文本行,失败时返回CHAR_MAX
string line=GetString();
如果(行==NULL)
返回CHAR_MAX;
//如果仅返回一个字符(可能带有
//提供了前导和/或尾随空格)
字符c1,c2;
如果(sscanf(行、%c%c、&c1和c2)==1)
{
自由线;
返回c1;
}
其他的
{
自由线;
printf(“重试:”);
}
}
}
/*
*从标准输入中读取一行文本并返回等效文本
*尽可能精确地加倍;如果文本不代表
*双击,提示用户重试。前导和尾随空格
*被忽略了。为简单起见,不会检测到溢出和下溢。
*如果无法读取行,则返回DBL_MAX。
*/
double-GetDouble(无效)
{
//尝试从用户处获得一个双精度
while(true)
{